1. 40 points In mathematics, the Fibonacci numbers are the series of number that
ID: 3665919 • Letter: 1
Question
1. 40 points In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.... In mathematical notation the sequence Fn of Fibonacci number is defined by the following recurrence relation:Fn=Fn-1+Fn-2
With the initial values of F0=0 and F1=1. Thus, the next number in the series is the sum of the previous two numbers. Write a program that asks the user for a positive integer N and generate the Nth Fibonacci number. Your main function should handle user input and pass that data to a function called Fib that takes n integer value N as input and a reference parameter that is assigned the Nth Fibonacci number. 1. 40 points In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.... In mathematical notation the sequence Fn of Fibonacci number is defined by the following recurrence relation:
Fn=Fn-1+Fn-2
With the initial values of F0=0 and F1=1. Thus, the next number in the series is the sum of the previous two numbers. Write a program that asks the user for a positive integer N and generate the Nth Fibonacci number. Your main function should handle user input and pass that data to a function called Fib that takes n integer value N as input and a reference parameter that is assigned the Nth Fibonacci number. 1. 40 points In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.... In mathematical notation the sequence Fn of Fibonacci number is defined by the following recurrence relation:
Fn=Fn-1+Fn-2
With the initial values of F0=0 and F1=1. Thus, the next number in the series is the sum of the previous two numbers. Write a program that asks the user for a positive integer N and generate the Nth Fibonacci number. Your main function should handle user input and pass that data to a function called Fib that takes n integer value N as input and a reference parameter that is assigned the Nth Fibonacci number.
Explanation / Answer
//program to generate fibonacci series and to display nth fibonacci number
#inlcude<stdio.h>
#include<conio.h>
int fib(int n, int*fibNo);//function prototype which is a function declaration before calling, defining a funtion
void main() //execution begins at main function
{
//declaration of variables
int n;
int* fibNo = 0; //normal variable holds value whereas pointer variable holds the address of the value
clrscr(); //clears the screen , its a build-in function so conio.h header file is required.
printf(" enter the integer vaue");
scanf("%d",n);
printf(" n = %d",n);
*fibNo=fib(n,fibNo); //function call made. we are sending value of n and address of the variable where result gets stored.
//prints the desirable out which is nth fibonacci number
printf("%dth fibnocci number is = %d",n.*fibNo);
getch();
}
int fib(int n, int*fibNo) //function definition that are to be called in main function to perform actual task
{
int i,f0=0,f1=1,f2;
*fibNo=0; //initialize the value of the pointer to 0;
f2=f0+f1; //add 0 and 1 which is the content of f0 and content of f1 and assign to the variable f2
for(i=2;i<n;i++) // the value of i is 2 since first two terms are already initialized
{
f0=f1;
f1=f2;
*fibNo=f2;
f2=f0+f1;
}
return *fibNo; // the nth fibonnaci number is stored in the variable *fibNo which is a pointer variable.
}
//*fibNo is the pointer variable which holds the value of the nth fibonacci number. That is what we are interested with.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.