Pagini recente » Cod sursa (job #801762) | Cod sursa (job #536934) | Cod sursa (job #953596) | Cod sursa (job #981234) | Cod sursa (job #1322019)
#include <stdio.h>
#include <conio.h>
int *a;
////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;
}