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