answersLogoWhite

0

We use long int or long instead of int as for larger terms the number is also larger.

Code is as follows:

#include

#include

long fib(long n);

void main()

{

long res,n;

int i;

printf("Enter the number of terms of the Fibonacci Series:\t");

scanf("%d",&n);

for(i=0;i

{

res=fib(i);

printf("\n %d",res);

}

_getch();

}

long fib(long n)

{

long res;

if(n==0n==1)

return (n);

else

res=fib(n-1)+fib(n-2);

return(res);

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering

Write a program to print the Fibonacci series in php upto input value using recursive function?

The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0 F1 = 1 Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following: function fibonacci($n) { if($n 1) return 1; //F1 else return fibonacci($n - 1) + fibonacci($n - 2); //Fn } This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script. for($i = 0; $i < 15; $i++) { echo fibonacci($i) . "<br />"; } So your final result would look like. <?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i < 15; $i++) { echo fibonacci($i) . "<br />"; } ?>


Write a java program to print the last digit in Fibonacci series?

Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.


Program to perform Fibonacci search in c language?

#include<stdio.h> int main(){ int a[10],i,n,m,c=0; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements of the array: "); for(i=0;i<=n-1;i++){ scanf("%d",&a[i]); } printf("Enter the number to be search: "); scanf("%d",&m); for(i=0;i<=n-1;i++){ if(a[i]==m){ c=1; break; } } if(c==0) printf("The number is not in the list"); else printf("The number is found"); return 0; }


Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


How do you check whether a given number n is a Fibonacci number or not?

In a Fibonacci sequence, sum of two successive terms gives the third term.... here is the Fibonacci sequence: 0,1,1,2,3,5,8,13,21,34,55,89,144........ General formula to generate a Fibonacci sequence is """Fn= Fn-1 + Fn-2""" To check whether a number is Fibonacci or not follow the following steps: 1) Get the number as input from user. 2) Fix the first two numbers of sequence as 0 and 1. 3) put a sentinel loop with upper limit being the input number. 4)in the body of loop generate the next number in sequence in each iteration and continue swapping the values as follows: a=0 b=1 next=a+b while (next< input) a=b b=next next=a+b wend 5) lastly when program exits the loop compare the last number of sequence with the input number if they are equal then number is Fibonacci otherwise not. otherwise the last term of sequence will be less than the input number.

Related Questions

Write a Fibonacci function then takes an input from the user in main program and pass to function which prints Fibonacci series up to this number in c language by using while statement?

#include#includevoid fibonacci(int x){int f=0,m=-1,n=1,i=0;while(i


Write a Fibonacci function then takes an input from the user in main program and pass to function which prints Fibonacci series up to this number in c language by using for statement?

#include<stdio.h> #include<conio.h> void fibonacci(int x) { int f=0,m=-1,n=1,i; for(i=0;i<x;i++) { f=m+n; printf("%d\n",f); m=n; n=f; } } void main() { int n; clrscr(); printf("\nEnter the limit:"); scanf("%d",&n); fibonacci(n); getch(); }


Write a program to print the Fibonacci series in php upto input value using recursive function?

The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0 F1 = 1 Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following: function fibonacci($n) { if($n 1) return 1; //F1 else return fibonacci($n - 1) + fibonacci($n - 2); //Fn } This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script. for($i = 0; $i < 15; $i++) { echo fibonacci($i) . "<br />"; } So your final result would look like. <?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i < 15; $i++) { echo fibonacci($i) . "<br />"; } ?>


What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


Is 13 a Fibonacci number?

the first seven Fibonacci numbers are 1,1,2,3,5,8,13. 13 is a Fibonacci number.


What is 22nth Fibonacci number?

The 22nd Fibonacci number is 17,711


What is the twelfth Fibonacci number?

The twelfth Fibonacci number is 144.


What is the 365th Fibonacci number?

The 365th Fibonacci number is 8531073606282249384383143963212896619394786170594625964346924608389878465365.


What is the 100th Fibonacci number?

The 100th Fibonacci number is 354,224,848,179,261,915,075.


Which is not Fibonacci number 89 or 123?

123 is not a Fibonacci number.


How do you write a program using function that counts the number of vowels in a string in java language?

Use text-editor notepad++


What is the 18th Fibonacci number?

How to answer with formula