반응형
for
#include <stdio.h> int main() { int n, count, sum = 0; printf("Enter a positive integer: "); scanf("%d", &n); // for loop terminates when n is less than count for(count = 1; count <= n; ++count) { sum += count; } printf("Sum = %d\n", sum); return 0; }
결과
gcc -o loop loop.c hacker@HACKER:~/c$ ./loop Enter a positive integer: 10 Sum = 55
반응형