display fibonacci series upto n terms using recursive function.
Answers
Answered by
1
Answer: .
Explanation:
Program:
// Include necessary header files
#include<stdio.h>
// Declare a recursive function
int fib(int);
// Define a recursive to obtain a Fibonacci series
int fib(int m)
{
if(m == 0 || m == 1)
return m;
else
return(fib(m-1) + fib(m-2));
}
// Define a main function
int main()
{
// Declare variable to ask the number of terms from user
int m, n= 0, j;
// Prompt a message to ask the number of terms from user
printf("Enter Total terms: ");
// Use scanf() function to store the value entered by a user
scanf("%d", &m);
// Use loop to display the Fibonacci series
printf("Fibonacci series: ");
for(j = 1; j <= m; j++)
{
// Call the recursive to get the required series
printf("%d ", fib(n));
n++;
}
return 0;
}
Learn more: brainly.in/question/14242007
Similar questions
Political Science,
2 months ago
Chemistry,
4 months ago
Math,
4 months ago
Math,
11 months ago
Computer Science,
11 months ago