Practice Questions on Control & Conditional Statements in C
These practice problems will help reinforce your understanding of control and conditional statements in C.
Try implementing each one and testing edge cases!
1. Write a C program to check if a number is even or odd using if-else.
2. Modify the above to also handle negative numbers with a separate message.
3. Create a program using switch-case to perform +, -, *, / operations on two integers.
4. Write a program that uses nested if to determine the largest of three numbers.
5. Write a loop that prints all even numbers from 1 to 100 using a for loop.
6. Convert the above program using a while loop.
7. Write a program that prints a multiplication table of a given number using do-while.
8. Implement a program to sum digits of a number using a while loop.
9. Write a program to print numbers from 10 to 1 using a decrementing for loop.
10. Create a program that counts the number of positive and negative numbers entered by the user until 0 is entered.
11. Write a program to demonstrate break statement inside a loop to exit on a specific condition.
12. Write a program using continue statement to skip printing multiples of 3 from 1 to 20.
13. Develop a menu-driven program using switch to simulate a basic calculator.
14. Write a program with a nested if-else to check if a year is a leap year.
15. Create a program that prints the pattern below using nested loops:■ 1■ 1 2■ 1 2 3■ 1 2 3 4
16. Write a program to find factorial of a number using while loop.
17. Create a program to reverse a number using a do-while loop.
18. Write a program to print all prime numbers between 1 and 100 using nested loops.
19. Implement a program to check if a character is a vowel or consonant using switch.
20. Write a program that demonstrates the use of ternary operator instead of if-else.