Write a program to display the following the fibonanci squence numbers using iteration(for).
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
#include<iostream.h>
{
int first,second,third;
int i;
first = 0;
second = 1;
cout << endl << first << ", " << second << ", ";
for(i= 1; i<=8; i++)
{ third = first + second;
first = second ;
second = third;
cout << third << ", ";
cout << third << ", ";
}
}
}
No comments:
Post a Comment