BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/index.php)
-   Object Oriented Programming (http://bzupages.com/forumdisplay.php?f=322)
-   -   Program to compute the fibonacci series (http://bzupages.com/showthread.php?t=14662)

bonfire 09-03-2011 12:09 AM

Program to compute the fibonacci series
 
1 Attachment(s)
Program to compute the fibonacci series

#include
#include

void main()
{
clrscr();
int a,b,x,y,num1,ct;
a=0;
b=1;
cout << "Enter the number of terms (less than 25) : " << endl;
cin>>num1;
cout << a << endl;
cout << b << endl;
for(ct=1;ct<=num1-2;ct++)
{
x=a+b;
cout << x << endl;
y=a;
a=b;
b=x;
}
getch();
}
This program takes in the number of terms num1 in the fibonacci series (less than 25) as a screen input from the user.
It then computes the fibonacci series and prints it out using the 'cout' command.

Sample Input
12
Sample Output
0
1
1
2
3
5
8
13
21
34
55
89


All times are GMT +5. The time now is 04:02 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.