Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
682 views
in Computer by (69.4k points)

Write a function fibonacci() that takes an int argument n and prints first n elements of Fibonacci series. (A function series is where each successive number is the sum of preceding two elements. For example, 0 1 1 2 3 5 8 ….. is a Fibonacci series)

1 Answer

0 votes
by (61.3k points)
selected by
 
Best answer

#include<iostream.h>

#include<stdio.h>

#include<conio.h>

int Fibonacci(int);

void main()

{

 int n, i = 0, c;

 clrscr();

 cout<<"enter number :";

 cin>>n;

 cout<<"Fibonacci series\n";

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

 {

 cout<<Fibonacci(i)<<end1;

 i++;

 }

 getch();

}

int Fibonacci(int n)

{

 if ( n == 0 )

 return 0;

 else if ( n == 1 )

 return 1;

 else

 return ( Fibonacci(n-1) + Fibonacci(n-2) );

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...