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
Question
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
Solution
To determine how many times the following loop will be executed, we need to analyze the code.
The loop condition is "while (i <= 32767)", which means the loop will continue executing as long as the value of "i" is less than or equal to 32767.
The initial value of "i" is 32766. Since 32766 is less than 32767, the loop will execute at least once.
Inside the loop, the value of "i" is incremented by 1 using the statement "i = i + 1".
Therefore, in each iteration of the loop, the value of "i" will increase by 1.
The loop will continue executing until the value of "i" becomes greater than 32767.
Since the maximum value of an integer in many programming languages is 32767, the loop will execute only once.
Therefore, the correct answer is b. 1 time.
Similar Questions
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
How many times will the printf statement be executed?main( ){unsigned int i=3; while( i >=0)printf( "%d", i--);}A0
How many times the following loop will be executed? for(; ;){ }Which of the following is true? a. The loop will execute exactly once b. The loop will not execute at all c. The loop will execute infinite times d. It will give a compile-time error
How many times will the loop run?i=2while(i>0): i=i-1
How many times is the body of the loop executed in the code above?
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.