본문 바로가기
C 언어

for

by SpeeDr00t 2016. 7. 12.
반응형

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
반응형

'C 언어' 카테고리의 다른 글

do while  (0) 2016.07.12
while  (0) 2016.07.12
ptrace  (0) 2016.07.09
mmap  (0) 2016.07.09
stack_protector  (0) 2016.07.09