"Algorithm Notes" Section 2.4-C/C++ Quick Start -> Loop Structure Example 5-1-3 Summation of Continuous Natural Numbers

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;
}

Guess you like

Origin blog.csdn.net/DoMoreSpeakLess/article/details/109881083