示例#1
0
int recursive_fib(int n)
{
	int ret = n;
	if(ret >= 2)
		ret = recursive_fib(n-1) + recursive_fib(n-2);
	return ret; 
}
int recursive_fib(int val){	//recursive fibonacci function, takes the value as input and returns the result
	
	if(var==0)		//exception case, fib(0)=0!
		return 0;
	if(var==1)		//same, fib(1)=1!!
		return 1;
	return recursive_fib(var-1)+recursive_fib(var-2); //recursive call to the function

}//end of recursive_fib
int main(int argv, char * argc[])
{
  uint64_t index;
  char * end;
  clock_t startTime;
  clock_t endTime;
  
  if (argv != 2)
  {
    printf("usage: %s <number-of-values>", argc[0]);
    
    return 1;
  }
  
  index = strtoull(argc[1], &end, 10);

  startTime = clock();
  
  printf("%" PRIu64 " ", recursive_fib(index));
  
  endTime = clock();
  
  printf("Total time to calculate %" PRIu64 "(th) Fibonacci element: %f\n", index, (double) ((endTime-startTime) / CLOCKS_PER_SEC));
  
  return 0;
}
int main(void){	//the main function ^^

	int val;	//the value entered, for which we calculate the fib number
	int result;	//the result to be displayed
	
	
	printf("Please enter the value: ");	//ask the user for input
	scanf("%d", &val);
	
	result= recursive_fib(var);	//call recursive_fib function, assign the outcome to the result
	
	printf("The fibonacci result for the value entered is: %d \n ", result);	//display the result to the user!
	
	return 0;

}//end of main function
示例#5
0
int main(int argc, char** argv)
{
	printf("%d\n", recursive_fib(10));
	printf("%d\n", iterative_fib(10));
}