문제
f_n = f_n-1 + f_n-2 의 점화식을 가지는 피보나치 수열을 구현하라.
코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void main() | |
{ | |
int i, value_new, value_1, value_2; | |
i = 0; | |
value_1 = 1; | |
value_2 = 0; | |
while (i < 24) { // 피보나치 수열에 해당하는 24개의 숫자를 다 찾으면 반복문은 종료된다. | |
value_new = value_1 + value_2; | |
if (!(i % 12)) { | |
printf("\n"); | |
} | |
printf("%6d", value_new); | |
value_2 = value_1; | |
value_1 = value_new; | |
i++; | |
} | |
printf("\n"); | |
} |
'Computer Science > Problem Solving' 카테고리의 다른 글
[알고리즘 문제풀이 전략] 소수 구하기 by C언어 (1) | 2017.08.19 |
---|---|
[알고리즘 문제풀이 전략]05 임의의 숫자 배수의 개수와 합 구하기 by C언어 (0) | 2017.08.19 |
[알고리즘 문제풀이 전락]02 숫자 맞추기 byC언어 (0) | 2017.08.19 |
[알고리즘 문제풀이 전략]01-10진수와 16진수 변환 프로그램 by C언어 (0) | 2017.08.18 |
[tryhelloworld]JadenCase문자열 만들기 by파이썬 (1) | 2017.08.16 |