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<<“nt”;

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<<“nt”;
}

getch();
}

Leave a Comment

Your email address will not be published. Required fields are marked *