Pagini recente » Cod sursa (job #1511562) | Cod sursa (job #848305) | Cod sursa (job #786613) | Cod sursa (job #932307) | Cod sursa (job #1322029)
#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;
}