Demo entry 6359683

2

   

Submitted by anonymous on Apr 29, 2017 at 09:57
Language: C. Code size: 639 Bytes.

#include <stdio.h>
#pragma warning (disable : 4996)

int Fibo1(int num)
{
	if (num == 0)
		return 0;
	if (num == 1)
		return 1;

	return Fibo1(num - 1) + Fibo1(num - 2);
}

int Fibo2(int num)
{
	int pp = -1, p = 1;
	int result = 0;
	for (int i = 0; i <= num; i++)
	{
		result = pp + p;
		pp = p;
		p = result;

		printf("%d ", result);
	}
	return 0;
}
int main()
{
	int num;

	printf("정수 N을 입력하세요 : ");
	scanf("%d", &num);

	printf("재귀함수를 사용한 함수의 경우 : ");
	for (int i = 0; i <= num; i++)
	{
		printf("%d ", Fibo1(i));
	}
	printf("\n");
	printf("반복문을 사용한 함수의 경우 : ");
	Fibo2(num);
	printf("\n");
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).