Entri Populer

Selasa, 25 Januari 2011

Program to compute the fibonacci series.


#include <iostream.h>
#include <conio.h>

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.

Tidak ada komentar:

Posting Komentar