C programming practice questions focused on operators, if-else, loops, and switch-case.
🔹 Operators
What will be the output of the following code?
int a = 5, b = 2; printf("%d", a / b);Predict the result:
int x = 10; x += 5 * 2; printf("%d", x);What will be stored in
c?int a = 5, b = 3; int c = a % b;Evaluate:
int x = 2, y = 3; printf("%d", x && y);- Which operator has higher precedence:
*or+? - Write an expression using ternary operator to find the maximum of two numbers
aandb. Find the output:
int a = 4; printf("%d %d", a++, ++a);What will be the output?
int x = 5; printf("%d", x > 3 && x < 10);Predict:
int x = 0; printf("%d", !x);If
a = 2, b = 3, c = 4, evaluate:a += b *= c; printf("%d %d %d", a, b, c);
🔹 If-Else
- Write a program to check if a number is even or odd using
if-else. Predict the output:
int x = 10; if (x = 0) printf("Yes"); else printf("No");- Write a program to find the largest of three numbers using nested
if-else. Given
int x = -5;, what will this print?if (x) printf("True"); else printf("False");What is the output?
int a = 10; if (a > 5) if (a > 15) printf("Hello"); else printf("World");- Write a program using
if-elseto check whether a character is a vowel or consonant. Fix the error:
if (x > 5); printf("Greater");- Write a program to check whether a number is positive, negative, or zero.
🔹 Loops
- Write a program to print numbers from 1 to 10 using a
forloop. - Write a program to print the sum of first 100 natural numbers using a
whileloop. Predict the output:
int i = 0; while (i < 5) { printf("%d ", i); i++; }What is the output?
int i = 1; do { printf("%d ", i); i++; } while (i < 3);- Write a program to print the multiplication table of 5.
- Write a program to find the factorial of a number using a loop.
Predict the output:
for (int i = 0; i < 5; i++); printf("Hello");- Write a program to print even numbers from 1 to 20 using a
forloop. - Write a program to reverse a number (e.g., input
1234→ output4321). What is the output?
int i; for (i = 1; i <= 10; i++) { if (i == 5) break; printf("%d ", i); }What will this print?
for (int i = 1; i <= 5; i++) { if (i == 3) continue; printf("%d ", i); }
🔹 Switch-Case
- Write a program using
switchto check the day of the week (1 = Monday, …, 7 = Sunday). What is the output?
int x = 2; switch (x) { case 1: printf("One"); break; case 2: printf("Two"); case 3: printf("Three"); break; default: printf("Other"); }- Write a
switchprogram to check whether a given character is a vowel (a, e, i, o, u). Predict:
int x = 4; switch (x) { default: printf("Default"); case 4: printf("Four"); }- Can a
switchstatement work withfloatvalues? Why or why not? - Write a program using
switchto perform a basic calculator (addition, subtraction, multiplication, division).