Computer Science, asked by dondon04943, 4 months ago

#include<stdio.h>

int main()
{

int n;

for(n = 7; n!=0; n--)

printf("n = %d", n--);

getchar();

return 0;
}
output???​

Answers

Answered by nisargand2018
1

the answer is infinite loop

Answered by ankhidassarma9
0

Answer:

n = 7n = 5n = 3n = 1n = -1n = -3n = -5n = -7n = -9n = -11n = -13 ..... and so on.

it will be an infinite loop

Explanation:

• Consider the given for loop. It has only one statement in body i.e. printf("n = %d", n--); initial value of loop variable n is 7 . Printf() first prints the value of n i.e. 7 and then n-- of printf() function will execute and value of n will be 6.

• Now the execution control will be back to the for loop where the condition (n!=0) will be checked . As the condition is true , n-- statement of for loop will execute and n will turn 5.

• This value of n (i.e. n=5) will be printed in loop body and after that the value of n will become 4 by the statement n-- of printf()function and n will be 3 by the n-- statement of for loop.

• Hence we can see that n is decrementing by 2 with each execution of for loop body and it’s value will be 7 ,5,3,1,-1,-3,-5 and so on .

n will never be 0 so the for loop will never be terminated and will become an infinite loop.

Similar questions