When I run the program the printf is not printing.
#include <stdio.h>
void main()
{
int num, i=1 ;
scanf("%c",&num);
for(i=1; 1<num; i++);
printf("Hello World");
return 0;
}
When I run the program the printf is not printing.
#include <stdio.h>
void main()
{
int num, i=1 ;
scanf("%c",&num);
for(i=1; 1<num; i++);
printf("Hello World");
return 0;
}
Remove the ;
after your for
loop. It acts as an empty statement and hence your printf
isn't inside the for
loop.
#include <stdio.h>
void main()
{
int num, i=1 ;
scanf("%c",&num);
for(i=1; i<num; i++)
printf("Hello World");
return 0;
}
#include <stdio.h>
int main(){
int num;
//%d means you want to read an integer value where as %c is used for reading a character
scanf("%d",&num);
//Remove the semicolon after for loop
for(int i=0; i<num; i++)
printf("Hello World\n");
return 0;
}
$ gcc loop.c && ./a.out
4
Hello World
Hello World
Hello World
Hello World