0% found this document useful (0 votes)
12 views3 pages

Unit 5

The document contains a series of short and long questions related to programming concepts, including conditional control structures, logic gates, and loops. It covers topics such as 'if' statements, switch statements, and the significance of break and default statements. Additionally, it includes programming exercises and explanations of loop behavior, particularly focusing on while loops and infinite loops.

Uploaded by

Sabiha Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Unit 5

The document contains a series of short and long questions related to programming concepts, including conditional control structures, logic gates, and loops. It covers topics such as 'if' statements, switch statements, and the significance of break and default statements. Additionally, it includes programming exercises and explanations of loop behavior, particularly focusing on while loops and infinite loops.

Uploaded by

Sabiha Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Unit 4

SHORT QUESTION
1. . What is a conditional control structure?
2. Define the 'if' 1 statement in programming.
3. 2 How does an 'if-else' statement differ from a simple 'if' statement? Or What is a nested 'if'
statement?
4. Explain the purpose of the 'switch' statement.
5. What is a logic gate?
6. . What is the function of an AND gate?
7. What is the significance of the break and default statement in a 'switch' case?
8. What does a NOT gate do?
9. What is the difference between NOR and OR gates?
10. What is Boolean expression?
11. What is a truth table?
12. 11 Write a program to print larger out of two numbers.
13. Diff b/w syntax and semantic
14. Diff b/w sequence and selectipm
15. Why

LONG Questions
1. Draw truth table of and logic gate of
2. Simplify through K-Map
1. 3 Write a program to print grades f students using switch statement:
2. Marks >= 90: Grade A, Marks >= 80 and < 90: Grade B, Marks >= 70 and < 80: Grade C, Marks >=
60
3. 70: Grade D, Marks < 60: Grade F
4. What is a nested 'if' statement? Explain with example
5.
UNIT 5
why while loop is called conditional loop
"A while loop is based on a test condition, and the body of the loop executes as long as the test
condition is true. Once the condition becomes false, the loop stops executing. That’s why it is called
a conditional loop because it depends on a test condition."

OR
A while loop is called a conditional loop because it continues to execute as long as a specified condition
remains true. The loop checks the condition before each iteration, and if the condition is false, the loop
stops
The loop runs only if the condition is True.
Once the condition becomes False, the loop terminates.
what will happen if a loop has no condition

 For Loop:

 When you write a for loop like this: for(;;)


It means there is no condition to stop the loop.
 Result: It will run forever until you use a command like break inside the loop to exit it.

 While Loop:

 If you write a while loop with a condition that is always true (for example, while(1))
The loop's condition never becomes false.
 Result: It will also run endlessly until you explicitly stop it with something like a break
statement.

1.  Do-While Loop:
o Similarly, a do-while loop set up like this:

do {k.j
// Your code here
}
while (1);

Has a condition that is always true.

o Result: It will keep executing its block over and over until an internal command
(like break) ends the loop.

OR
If a loop has no condition, it will run indefinitely, creating an "infinite loop" where the code inside the
loop will repeat endlessly until the program is manually stopped, as there's no mechanism to tell the loop
when to stop without a j,yiyucondition to check.
1. How does while loop work?
2. What is the role of initialization in for loop?

Write a program to execute


*****
****
***
**
*

#include<stdio.h>
Void main()
{
int i = 5, j;

// Outer do-while loop for rows


do {
j = 1; // Initialize j for each row

// Inner do-while loop for printing stars in the current row


do {
printf("*");
j++;
} while(j <= i);

printf("\n"); // Move to the next line after printing the row


i--; // Decrease the count of stars for the next row
} while(i >= 1);

return 0;
}

3. Which loop is best to execute at least once


4. What do you meant by loop control variable

You might also like