C language: whether to continue every 100 units or not

Asked 1 years ago, Updated 1 years ago, 274 views

for (i = 1; i <= 1000; i++) {
        if (i % 7 == 0)
            printf("%d ", i);

        if (i == 100 || i==200 || i==300 || i==400 || i==500||i==600||i==700||i==800||i==900||i==1000) {
            printf("Continue(y/n)? ");
            scanf("%c", &a);
            if (a == 'y')
                continue;
            else
                break;
        }

It's a multiple of 7 from 1 to 1000 Every time it's over 100, I'm asking if you're going to continue What's wrong?

c

2022-10-27 00:00

1 Answers

scanf("%c", &a);

Change the top line as below. If you look closely at the front of %c of the code below, you can see the space bar.

scanf(" %c", &a);


2022-10-27 00:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.