Knowee
Questions
Features
Study Tools

What does the following program print?#include <stdio.h>int main() {    for (int i = 1; i < 10; i++) {        if (i % 2 == 0)            continue;        printf("%d ", i);    }    return 0;}

Question

What does the following program print?#include <stdio.h>int main() {    for (int i = 1; i < 10; i++) {        if (i % 2 == 0)            continue;        printf("%d ", i);    }    return 0;}

🧐 Not the exact question you are looking for?Go ask a question

Solution

The program prints the odd numbers from 1 to 9. Here's how it works:

  1. The for loop initializes i to 1 and will continue as long as i is less than 10, incrementing i by 1 after each loop.

  2. Inside the loop, the if statement checks if i is divisible by 2 (i.e., if i is an even number). If it is, the continue statement is executed. This skips the rest of the current iteration and goes straight to the next iteration of the loop.

  3. If i is not divisible by 2 (i.e., if i is an odd number), the program skips the if statement and executes the printf statement, which prints the value of i followed by a space.

  4. This process repeats until i is no longer less than 10.

So, the output of the program is: 1 3 5 7 9

This problem has been solved

Similar Questions

What will print out when the following code runs?

What will be the output of the following program?

What is the output of the following program :print "Hello World"[::-1]

What is the output for the following code?

What does the program below display?full_name = "Jane"full_name = full_name   + "Brown"print( full_name  )*

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.