Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Exercise.

1. Question: What will be the output of the following code snippet?

#include <stdio.h>

int main() {

int x = 10;

if (x > 5) {

printf("x is greater than 5\n");

return 0;

Answer: The output will be: `x is greater than 5`

2. Question: What is the output of the following code?

#include <stdio.h>

int main() {

int x = 5;

if (x % 2 == 0) {

printf("x is even\n");

} else {

printf("x is odd\n");

return 0;

Answer: The output will be: `x is odd`

3. Question: What will be the output of the following code snippet?

#include <stdio.h>

int main() {

int x = 5;
if (x == 5) {

printf("x is equal to 5\n");

} else if (x == 10) {

printf("x is equal to 10\n");

} else {

printf("x is neither 5 nor 10\n");

return 0;

Answer: The output will be: `x is equal to 5`

4. Question: What does the following code print?

#include <stdio.h>

int main() {

int x = 10;

if (x > 15) {

printf("x is greater than 15\n");

printf("End of program\n");

return 0;

Answer: The output will be: `End of program`

5. Question: What is the output of the code below?

#include <stdio.h>

int main() {

int x = 20, y = 30;

if (x == 20 && y == 30) {

printf("x is 20 and y is 30\n");


}

return 0;

Answer: The output will be: `x is 20 and y is 30`

6. Question: What does the following code snippet print?

#include <stdio.h>

int main() {

int x = 7;

if (x > 5) {

printf("x is greater than 5\n");

} else {

printf("x is less than or equal to 5\n");

return 0;

Answer: The output will be: `x is greater than 5`

7. Question: What is the output of the following code?

#include <stdio.h>

int main() {

int x = 10;

if (x != 5) {

printf("x is not equal to 5\n");

return 0;

Answer: The output will be: `x is not equal to 5`


8. Question: What will be the output of this code?

#include <stdio.h>

int main() {

int x = 10, y = 20;

if (x > y) {

printf("x is greater than y\n");

} else {

printf("x is less than or equal to y\n");

return 0;

Answer: The output will be: `x is less than or equal to y`

9. Question: What does the following code print?

#include <stdio.h>

int main() {

int x = 12;

if (x % 2 == 0) {

printf("x is even\n");

} else {

printf("x is odd\n");

return 0;

Answer: The output will be: `x is even`

10. Question: What is the output of the following code?

#include <stdio.h>
int main() {

int x = 0;

if (x) {

printf("x is true\n");

} else {

printf("x is false\n");

return 0;

Answer: The output will be: `x is false`

You might also like