728x90
#include <stdio.h>
void pause()
{
int x;
fprintf(stderr, "종료하려면 아무키나 누르세요");
getch();
}
int fib_iter(int n)
{
if (n == 0)
return 0;
if (n == 1)
return 1;
int pp = 0;
int p = 1;
int result = 0;
for (int i = 2; i <= n; i++)
{
result = p + pp;
pp = p;
p = result;
}
return result;
}
void main()
{
printf("%d\n", fib_iter(10));
pause();
}
간단쓰.
728x90
'언어 > C' 카테고리의 다른 글
| [C] strlen, strcmp, strcpy, strcat (0) | 2023.04.06 |
|---|---|
| [C] 하노이탑 쌓기 (0) | 2023.04.05 |
| [C] 구구단 + 합 구하기 (0) | 2023.03.16 |
| [C] 소수 구하기, 소수의 합 구하기 (0) | 2023.03.16 |
| [C] scanf로 문자열 입력 받아 길이 알아보기 (0) | 2023.02.28 |