Thursday 28 June 2012

c++ program that display following triangle pattern.


for n=3;
pattern:      
       * * *
        * *
          *



#include <iostream>
using namespace std;

int main()
{
int i,j,k,x;
//input from user
cout<<"Enter a number ";
cin>>k;





for(i=k;i>0;i--)
{
for(x=0;x<k-i;x++)
{
cout<<" ";
}
for(j=1;j<=i;j++)
{
cout<<"* ";
}
cout<<"\n";
}
return 0;
}

No comments:

Post a Comment