Please look at the picture below: This is C programming only please. Name this p
ID: 3686645 • Letter: P
Question
Please look at the picture below:
This is C programming only please.
Name this program fib. c - Calculating Fibonacci numbers is a classic recursive algorithm. The basic recurrence relation for Fibonacci numbers is shown below. Write a program that recursively calculates the Fibonacci value for a number provided on the command line. Using a global variable, keep track of the number of calls to your recursive function. Your program should print out the calculated Fibonacci value and the number of calls to your recursive function that it took to compute this value. You see several sample outputs from this program belowExplanation / Answer
#include<stdio.h>
#include<stdlib.h>
int recursive_count = 0;
int fib(int n)
{
recursive_count++; // increasing count
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
int main (int argc, char *argv[])
{
int n = atoi(argv[1]);
int f = fib(n);
printf("fib(%d) = %d has %d recursive calls. ", n,f, recursive_count);
return 0;
}
/*
Output:
:~/Desktop/MyCode/april/1-5 april$ ./a.out 10
fib(10) = 55 has 177 recursive calls.
*/