Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

pausing a loop to read a character

pokafacepokaface Member Posts: 1

hey guys. c newbie here. i'm trying to write a loop that prints a table of squares from 1 to n, which pauses after every 24 squares and displays "Press enter to continue..". the program should use getchar () to read a character.

i have to far the loop to print the squares.. im stuck on pausing the program and using getchar () to continue

include <stdio.h>

int main()
{
int i, n;
printf("enter number n:");
scanf("%d",&n);

for (i=1; i<=n; i++) {

    printf("%d\t%d\n", i, i*i);
}
    return 0;

}

any would be appreciated..thanks a bunch

Comments

  • pokafacepokaface Member Posts: 1

    figured it out guys ..

    for (i=1; i<=n; i++) {
        while ((i%24)==0){
                getchar();
                printf("enter:");
                if( getchar()=='\n')
                break;
                }
        printf("%d\t%d\n", i, i*i);
    }
    
        return 0;
    

    }

    thanks again

Sign In or Register to comment.