C | Loops & Control Structure | Question 8
#include<stdio.h> int main() { int n; for (n = 9; n!=0; n--) printf ( "n = %d" , n--); return 0; } |
What is the output?
(A) 9 7 5 3 1
(B) 9 8 7 6 5 4 3 2 1
(C) Infinite Loop
(D) 9 7 5 3
Answer: (C)
Explanation: The program goes in an infinite loop because n is never zero when loop condition (n != 0) is checked. n changes like 9 7 5 3 1 -1 -3 -5 -7 -9 …
Quiz of this Question
Please Login to comment...