Example 5-1-1 Sum of Continuous Natural Numbers
Title description
Seek 1+2+3+…+100, that is, require a while statement to achieve the required sum of
input and
no
output
, and the end output will wrap.
Sample input Copy
No
sample output Copy
5050
#include <stdio.h>
int main(void) {
int i = 1;
int sum = 0;
while (i <= 100) {
sum += i;
i++;
}
printf("%d", sum);
return 0;
}