Unit 5
Unit 5
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:
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);
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?
#include<stdio.h>
Void main()
{
int i = 5, j;
return 0;
}