c++ program that display following triangle pattern.
for n=3;
1 1 2
3 5 8
13 21 34
#include <iostream>
using namespace std;
int main()
{
int i,j,k,f1,f2,f3;
//input from user
cout<<"Enter a number ";
cin>>k;
f2=1;
f1=0;
f3=1;
for(i=1;i<=k;i++)
{
for(j=1;j<=k;j++)
{
cout<<f3<<" ";
f3=f1+f2;
f1=f2;
f2=f3;
}
cout<<"\n";
}
return 0;
}
No comments:
Post a Comment