#include <stdio.h> int main(void) { long sum = 0L; int count = 10; int i,j; for(i = 1 ; i <= count ; i++ ){ sum = 0L; for(j = 1 ; j <= i ; j++ ) sum += j; printf("\n%d\t%ld", i, sum); } return 0; }
1 1 2 3 3 6 4 10 5 15 6 21 7 28 8 36 9 45 10 55
6.6.For statement | ||||
6.6.1. | for LOOP | |||
6.6.2. | Omit all three parts in for loop | |||
6.6.3. | The for loop with a comma operator | |||
6.6.4. | Initialize loop control variable outside the for statement | |||
6.6.5. | Use for loop to print a rectangle | |||
6.6.6. | Sum integers in for statement | |||
6.6.7. | for loop backward | |||
6.6.8. | indefinite loop: empty for | |||
6.6.9. | Nest if statement in for loop | |||
6.6.10. | Nest for loop: two different control variables | |||
6.6.11. | Use char variable to control for loop | |||
6.6.12. | Continue a for loop |