Example 5-1-2 Summing continuous natural numbers
Title description
Seek 1+2+3+…+100, that is, it is required to use the do…while statement to achieve
input and
no
output.
Calculate the result. Pay attention to the output line break at the end.
Sample input Copy
No
sample output Copy
5050
#include <stdio.h>
int main(void) {
int i = 1;
int sum = 0;
do {
sum += i;
i++;
} while (i <= 100);
printf("%d", sum);
return 0;
}