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