Tuesday 5 April 2016

Program to print following pattern using for loop in c++ language.

 //Wap to print following pattern using for loop in c++ language.
   //              *
   //           *     *
   //         *    *    *
  //       *    *     *     *
  //          *    *     *
  //             *    *
  //               *




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

void main()
{

int i,j,k,n;
clrscr();
cout<<"enter the no of rows:"<<endl;
for(i=1; i<=5; i++)
{
for( j=1;j<=5-i; j++)
{
cout<<"  ";
}
for(k=1; k<=i; k++)
{
cout<<" *  ";
}
cout<<"\n";
}
for(i=4;i>=1;i--)
{
for(j=1;j<=5-i;j++)
{
cout<<"  ";
}
for(k=1;k<=i;k++)
{
cout<<" ";
}
cout<<"\n";
}

getch();
}



Output:-

 

No comments:

Post a Comment