The Fibonacci sequence is the series of numbers: 0; 1, 1, 2, 3, 5, 8, 13,.... Th
ID: 3678139 • Letter: T
Question
The Fibonacci sequence is the series of numbers: 0; 1, 1, 2, 3, 5, 8, 13,.... The next number is found by adding up the two numbers before: F(n) = F(n - 1) + F(n - 2) and F(0) = 0 and F(1) = 1 Write a recursive function that takes an integer n as input and returns the nth number in the Fibonacci series. Write a program fibonacci.c that asks the user to enter an integer and uses the function above to print out the corresponding Fibonacci number. Your program must validate the input is positive. Write a recursive function that takes an array of decimals as input and prints it content in reverse order, each value on a separate line, always showing the sign. Write a program arrayReverse.c that asks the user to enter a number corresponding to the number of decimal values to be stored. Your program should then ask the user to enter those values and store them in an array. Use the function you wrote to print the array in reverse order. Write a recursive function that takes an integer as input and prints its digits in reverse order. Write a program intReverse.c that asks the user to enter an integer use the function you wrote to print the digits in reverse order.Explanation / Answer
/*Fibonacci*/
#include<stdio.h>
int fibonacci(int);
int main()
{
int n,i=0,c;
scanf("%d",&n);
for(c=1;c<=n;c++)
{
printf("%d,",fibonacci(i));
i++;
}
printf(" ");
return 0;
}
int fibonacci(int n)
{
if(n==0)
{
return 0;
}
else if(n==1)
{
return 1;
}
else
{
return fibonacci(n-1)+fibonacci(n-2);
}
}
/*Array Reversal*/
#include<stdio.h>
void PrintArray(int a[],int k)
{
int z;
if (k>0)
{
z= k-1;
printf("%d ",a[z]);
PrintArray(a,z);
}
return;
}
int main()
{
int n,i;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
PrintArray(a,n);
return 0;
}
/*Integer Reversal*/
#include<stdio.h>
int main(){
int num,reverse_number;
//User would input the number
printf(" Enter any number:");
scanf("%d",&num);
//Calling user defined function to perform reverse
reverse_number=reverse_function(num);
printf(" After reverse the no is :%d ",reverse_number);
return 0;
}
int sum=0,rem;
reverse_function(int num){
if(num){
rem=num%10;
sum=sum*10+rem;
reverse_function(num/10);
}
else
return sum;
return sum;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.