반응형
1. 문법
while (testExpression) { //codes }
2. 테스트 소스
#include <stdio.h> int main() { int number; long long factorial; printf("Enter an integer: "); scanf("%d",&number); factorial = 1; // loop terminates when number is less than or equal to 0 while (number > 0) { factorial *= number; // factorial = factorial*number; --number; } printf("Factorial= %lld", factorial); return 0; }
3. 결과
gcc -o while1 while1.c hacker@HACKER:~/c$ ./while1 Enter an integer: 10 Factorial= 3628800
반응형