Cod sursa(job #1322029)

Utilizator get0000lostSatmarean Paul get0000lost Data 19 ianuarie 2015 18:57:49
Problema Al k-lea termen Fibonacci Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 0.93 kb
#include <stdio.h>

int a[10000];

////keeps window open
//void keepwindowopen()
//{
//	printf("\n");
//	printf("Press any key to continue...");
//	char s[2] = "";
//	_getch(s);
//}

//computes the xth term of he fibbonacci series
int fibo(int x)
{
	int b = 0;
	if (x == 1 || x == 2)
		return 1;
	else
	{
		if (a[x] != 0)
			return a[x];
		else
			b = fibo(x - 1) + fibo(x - 2);
			a[x] = b;
			return b;
	}
}

//int* init()
//{
//	int *a;
//	a = (int*)malloc(100 * sizeof(int));
//	int i;
//	for (i = 0; i < 101; i++)
//		a[i] = 0;
//	return a;
//}



int main()
{
	//a = init();

	int x, fx;
	FILE *pf;
	pf = fopen("kfib.in", "r");
	
	fscanf(pf,"%d", &x);
	//printf("introduceti termenul: ");
	//scanf_s("%d", &x);
	fclose(pf);
	fx = fibo(x);
	/*printf("the %dth term is: %d", x, fx);
	keepwindowopen();*/
	pf = fopen("kfib.out", "w");
	fprintf(pf, "%d", fx);
	fclose(pf);
	return 0;
}