Knowee
Questions
Features
Study Tools

What will be the output of the following code?int i = 1;while(i<10){  if (i % 2 == 0)     cout << i << “ ”; i++;}

Question

What will be the output of the following code?int i = 1;while(i<10){  if (i % 2 == 0)     cout << i << “ ”; i++;}

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

Solution

The output of the code will be:

2 4 6 8

This is because the code is a loop that starts with i = 1 and increments i by 1 each time it runs, until i is no longer less than 10. Within the loop, it checks if i is divisible by 2 (i.e., if i is an even number). If i is even, it prints i followed by a space. So, it prints all the even numbers from 1 to 9.

Similar Questions

What will be the output of the following code?int num = 2;int count=0;while(num!= 0){if ( num & 01)count ++;num >>=1;}cout<< count;return 0;

CWhat is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}

What will be the result?1. int i = 10;2. while(i++ <= 10){3. i++;4. }5. System.out.print(i);10111213

What is the output of the programme below?public static void main(String[] args) {     int x = 0;     while (x < 10) {          if (x & 2 == 0) {               System.out.print(x + “ “);          }          x++;     }}

What is the output of the following code snippet?int i = 0;while (i < 5) {    if (i == 3)        break;    System.out.print(i + " ");    i++;}

1/3

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.