Home > Software design >  I can't seem to run the program and printf
I can't seem to run the program and printf

Time:01-12

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;
}

CodePudding user response:

Remove the ; after your for loop. It acts as an empty statement and hence your printf isn't inside the for loop.

CodePudding user response:

#include <stdio.h>

void main()
{
    int num, i=1 ;
    scanf("%c",&num);
    for(i=1; i<num; i  )
        printf("Hello World");
    return 0;
}

CodePudding user response:

Program :

#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;
}

Output :

$ gcc loop.c && ./a.out
4
Hello World
Hello World
Hello World
Hello World
  •  Tags:  
  • Related