Knowee
Questions
Features
Study Tools

How many times will the printf statement be executed?main( ){unsigned int i=3; while( i >=0)printf( "%d", i--);}A0

Question

How many times will the printf statement be executed?main( ){unsigned int i=3; while( i >=0)printf( "%d", i--);}A0

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

Solution 1

The printf statement will be executed 4 times. The initial value of i is 3. The while loop will continue to execute as long as i is greater than or equal to 0. On each iteration of the loop, the value of i is printed and then decremented by 1. So, the values printed will be 3, 2, 1, and 0. After printing 0, i is decremented to -1, which is not greater than or equal to 0, so the loop terminates.

Solution 2

The printf statement will be executed 4 times. The initial value of i is 3. The while loop will continue to execute as long as i is greater than or equal to 0. On each iteration of the loop, the printf statement is executed and then i is decremented by 1. So, the printf statement will be executed for i values 3, 2, 1, and 0. After i becomes -1, the condition of the while loop (i >= 0) is no longer true, so the loop terminates.

This problem has been solved

Similar Questions

How many times following loop will be executed?void main(){   int i = 32766;   while (i<= 32767)   {        printf("%d\n",i);         i = i + 1;     }}a.2 timesb.1 timesc.infinite timesd.loop will not be executed

In the following program, how many times will the for loop execute?#include<stdio.h> int main() {     int i=5;     for(;scanf("%d", &i); printf("%d", i));     return 0; }Select one:The for loop will execute only onceThe for loop will execute infinite timesThe for loop will not execute at allThe for loop will execute 5 times

Understanding while loopWrite the correct output in the blanks for the below C code?#include <stdio.h>void main() { int i = 3; while (i--) { int i = 100; i--; printf("i = %d ", i); }}

How many times i value is checked in the following C program? #include <stdio.h>    int main()    {        int i = 0;        while (i < 3)            i++;        printf("In while loop\n");    }4321

What is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); 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.