Multiple While questions

Asked 2 years ago, Updated 2 years ago, 143 views

... ... int sum=0, num=0, i=0;

while(i<5) { while(num<=0) {

printf(Enter a number greater than 0): ", i+1);
            scanf("%d", &num);
    }

sum+=num; num=0; i++; } printf("total: %d \n", sum); return 0; }

If I enter 5 integers greater than 0 in these codes, can I get out of while(num<=0)?

Even if I input 5 pieces, won't I not be able to go out to the first while door outside and continue to receive input by satisfying the conditions of the inside while door?

while-loop c

2022-09-22 19:54

1 Answers

Please take a look at the question writing tips and use the code block.

There is a part where num is reallocated to zero, so the condition of the inner while statement will always be true, so there will be an infinite loop.


2022-09-22 19:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.