Wednesday, February 11, 2015

C Program to print following triangle


         *
       *  *
      *    *
     *****


code:


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


void main()
{
clrscr();
int i,k,j,n;
cout<<"Enter size of triangle in odd number(min-5,ex-5,7,9):";
cin>>n;
cout<<"
";



for(i=1;i<=n;i+=2)
{
for(j=n;j>i;j-=2)
cout<<" ";
for(k=1;k<=i;++k)
{
if(i==n)
cout<<"*";
else
if(k==1||k==i)
cout<<"*";
else
cout<<" ";
}
cout<<"
";

}


getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.