hello,
i have tried compiling and running this code but how do i input a numeric value like 30 or 35? this is recursive fibonacci and all i need to do is check the output after program has finished execution. any suggestions would be of tremendous help. i just need to know how to enter a value.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
__int64 fibRecursive(int n)
{
if (n <= 0)
return 0;
if (n == 1)
return 1;
return fibRecursive(n - 1) + fibRecursive(n - 2);
}
__int64 fibIteration(int n)
{
__int64 ret = 0;
int i,j, iter;
i=0;
j=1;
if( n < 2)
return n;
for(iter=2; iter<=n; iter++)
{
ret=i+j;
i=j;
j=ret;
}
return ret;
}
int main(int argc, char* argv[])
{
__int64 val;
int n;
time_t t1, t2;
if(argc != 3)
{
printf("Usage %s iteration or recursive number\n", argv[0]);
_exit(1);
}
n = atoi(argv[2]);
t1 = time(NULL);
if(strcmp(argv[1], "iteration") == 0)
{
val = fibIteration(n);
}
else if(strcmp(argv[1], "recursive") == 0)
{
val = fibRecursive(n);
}
t2= time(NULL);
printf("n=%d, Val = %I64u, time spent is =%d\n", n, val, t2 - t1);
return 0;
}
i want to enter a number, let the program run because all i require is to check how much time it took the program to complete the calculation.