문제

내가 작성한 코드
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
int num;
scanf("%d",&num);
int result = 1;
for(int i = 1; i<=num; i++){
result *= i;
}
printf("%d\n", result);
return 0;
}
int형을 입력받은 다음에 for문을 이용해 1부터 num까지 차례대로 곱하게 해주었다
짧게 구현된 팩토리얼이랄까나...
그리고는 결과값 출력하게 했다
'C언어 > 주차별 문제' 카테고리의 다른 글
[3주차] 피라미드 (0) | 2023.04.18 |
---|---|
[3주차] 윤년 (0) | 2023.04.18 |
[2주차] 자동 계산기2 (0) | 2023.04.18 |
[2주차] 자동 계산기1 (0) | 2023.04.18 |
[2주차] 초보 C프로그래머2 (0) | 2023.04.18 |