answersLogoWhite

0


Best Answer

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

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

//This program will generate the Fibonacci numbers using recursion till a particular limit

#include<stdio.h>

int fib(int);

void main()

{ int limit;

printf("Enter the limit");

scanf("%d",&limit);

for(int i=0;fib(i)<=limit;i++)

printf("\n%d",fib(i));

}

int fib(int a)

{

if(a==0a==1)

return 1;

else

return (fib(a-1)+fib(a-2));

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

//program to find the fibonnacci series of n numbers.

#include <stdio.h>

void fibo(int);

void main()

{

int iLimit;

printf("Enter the number till which the fibonnacci series should be printed.");

scanf("%d",&iLimit);

fibo(iLimit);

}

void fibo(int iLimitnum)

{

int inum1,inum2,inum3;

int iadd;

inum1=0;

inum2=1;

int i;

printf("0 ");

for (i=0; ;i++)

{

iadd=inum1+inum2;

inum1=inum2;

inum2=iadd;

if(inum1 > iLimitnum)

break;

printf("%d ", inum1);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int n,c,a=0,b=1;

clrscr();

printf("Enter the number to generate febonacci series:");

scanf("%d",&n);

for(i=0;i<n;i++)

{

c=a+b;

printf("%d",c);

}

a=b;

b=c;

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<conio.h>

void main()

{

int n,f1,f2,f3;

clrscr();

printf("\n\n\t\tFIBONACCI SERIES\n");

printf("\nenter the number of terms required\n");

scanf("%d",&n);

printf("\nThe Fibonacci series is:\n");

f1=1;

f2=0;

for(i=1;i<=n;i++)

{

f3=f1+f2;

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

f1=f2;

f2=f3;

}

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Before you think about writing the code, write out the algorithm, what steps you need to do to get your result. You need to ask yourself what you do to find the next number in the series.

You'll need a global variable for each of the last two numbers (lets say X and Y), a temporary variable (int), some loops (and an index variable), and how many numbers in the series you want to be calculated and displayed.

If you want to use it as a function, you just put the code in a separate area to the main, and make it return a value.

Here are the basic steps for the Fibonacci function:

  1. Y = Temporary (for later)
  2. Work out the next number, Y = X + Y
  3. X = Temporary (basically, the old Y is the new X)
  4. return Y (the new number)

You can also work this out with arrays, which is probably a better solution, but needs more code to work out the laast two numbers in the array.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

I am not so sure about C++, but Python is somewhat similar.

def awesome_function()

number = input("The number you would like to use?")

for i in range(number)

print(i)

Great question! ^^

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

You cannot produce a Fibonacci sequence with a single number. Each number in the sequence is the sum of the previous two numbers, which traditionally begins with the numbers 0 and 1. Entering a single number n usually means you're looking for the nth number in the sequence.

Regardless, recursion is not the most efficient way of producing the Fibonacci sequence. Although the code may be cleaner, every recursion consumes more call stack space for no good reason, and ultimately slows down the generation of the sequence.

Iteration is the method of choice here. Although it requires a few more lines of code, this is more than offset by the speed of execution.

#include

using namespace std;

int Fib(

unsigned int n,

const unsigned int penultimate,

const unsigned int ultimate )

{

return( n ? Fib( --n, ultimate, penultimate + ultimate ) : ultimate );

}

int main()

{

unsigned int in = 1;

while( in )

{

printf( "Enter the Fibonacci number you're looking for (1-48): " );

if( scanf( "%u", &in ) 3 ? "rd" : "th",

fib );

}

}

}

return( 0 );

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

no...i want complete c code using stack

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: 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 using function in c plus plus language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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 &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } So your final result would look like. &lt;?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } ?&gt;


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&lt;stdio.h&gt; int main(){ int a[10],i,n,m,c=0; printf("Enter the size of an array: "); scanf("%d",&amp;n); printf("Enter the elements of the array: "); for(i=0;i&lt;=n-1;i++){ scanf("%d",&amp;a[i]); } printf("Enter the number to be search: "); scanf("%d",&amp;m); for(i=0;i&lt;=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&lt; 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&lt;stdio.h&gt; #include&lt;conio.h&gt; void fibonacci(int x) { int f=0,m=-1,n=1,i; for(i=0;i&lt;x;i++) { f=m+n; printf("%d\n",f); m=n; n=f; } } void main() { int n; clrscr(); printf("\nEnter the limit:"); scanf("%d",&amp;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 &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } So your final result would look like. &lt;?php function fibonacci($n) { if($n 1) return 1; else return fibonacci($n - 1) + fibonacci($n - 2); } for($i = 0; $i &lt; 15; $i++) { echo fibonacci($i) . "&lt;br /&gt;"; } ?&gt;


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


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

Use text-editor notepad++


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 the 365th Fibonacci number?

The 365th Fibonacci number is 8531073606282249384383143963212896619394786170594625964346924608389878465365.


What is 22nth Fibonacci number?

The 22nd Fibonacci number is 17,711


What is the 18th Fibonacci number?

the 18th of Fibonacci number is 2584.


What is the 100th Fibonacci number?

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


What is the twelfth Fibonacci number?

The twelfth Fibonacci number is 144.


Which is not Fibonacci number 89 or 123?

123 is not a Fibonacci number.