Find output of C programs (for loop) in C: Here, you will find some of the C programs based on for loop with the outputs and explanations.
Program-1
#include <stdio.h>
int main()
{
int i;
for(i=1; i<=10;i++)
printf("i=%d\n",i);
return 0;
}
Program-2
#include <stdio.h>
int main()
{
int i;
for(i=1; i<=10;i++);
printf("i=%d\n",i);
return 0;
}
Program-3
#include <stdio.h>
int main()
{
int i;
for(i=65; i<(65+26);i++)
printf("%c ",i);
return 0;
}
Program-4
#include <stdio.h>
int main()
{
int i;
for(i=1; -1; i++)
printf("%c ",i);
return 0;
}
Answer Program 1:
Output
Explanation
It’s a simple loop format, which will print value from 1 to 10.
Answer Program 2:
Output
Explanation
See the semicolon, after the for loop statement (loop is terminating without anybody), the printf statement is not a body of for loop.
Loop will be executed and when the value of i will be 11, program's execution reaches to the printf statement. Thus, the output will be i = 11.
Answer Program 3:
Output
Explanation
See the printf statement, here we are printing the value in character format (using "%c" format specifier) and the value of i is 65 to 90, which are the ASCII codes of Uppercase alphabets from A to Z. Thus, the output will be "A B C ... Z".
Answer Program 4:
Output
Explanation
See the conditional part of the loop statement, it is "-1" which is a non zero value and in C programming language a non zero value considered as "true", so this is a infinite loop.
need an explanation for this answer? contact us directly to get an explanation for this answer