Problem Solving using C Language

0 of 77 lessons complete (0%)
Back to lesson

Quiz: Conditional Statement Quiz

  1. 1. What will the following code output?

    1

    int a = 3;
    if (a > 0)
    {
    if (a < 10)
    {
    printf(“An”);
    }
    else
    {
    printf(“Bn”);
    }
    }

  2. 2. Which of the following is not true about the else statement?

    1
  3. 3. What does the following code output if x = 5?

    1

    if (x == 5)
    printf(“x is 5n”);
    else
    printf(“x is not 5n”);

  4. 4. What will the following code print if x = 6?

    1

    if (x > 0)
    if (x % 2 == 0)
    printf(“Evenn”);
    else
    printf(“Oddn”);
    else
    printf(“Negativen”);

  5. 5. In a nested if-else structure, how does the compiler determine which else matches which if?

    1
  6. 6. What is the output of the following switch statement?

    1

    int day = 2;
    switch (day) {
    case 1: printf(“Sundayn”); break;
    case 2: printf(“Mondayn”); break;
    case 3: printf(“Tuesdayn”); break;
    default: printf(“Invalid dayn”);
    }

  7. 7. What will the following code output?

    1

    int x = 4;
    if (x == 5)
    printf(“x is 5n”);
    else if (x == 4)
    printf(“x is 4n”);
    else
    printf(“x is unknownn”);

  8. 8. What is the output of the following code?

    1

    int num = 10;
    if (num > 10)
    printf(“Greater than 10n”);
    else if (num == 10)
    printf(“Equal to 10n”);
    else
    printf(“Less than 10n”);

  9. 9. What happens if there is no break statement in a switch case?

    1
  10. 10. What is the output of the following code?

    1

    int a = 10;
    if (a > 5)
    {
    printf(“Greatern”);
    }
    printf(“Endn”);