"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Friday, March 5, 2010

Write a program using nested loops to produce the following design:

                                *               
                  *      *           
               *            *        
            *                  *     
          *                       *  
       * * * * * * * * * * *


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

void main()
{

int n;

cout<<"\n Enter height :";
cin>>n;

for(int r = 1, sp = n-1 ; r<= n ; r++, sp--)
{
for (int k = 0; k<=sp ; k++)
cout<< " " ;

for(int c = 1; c < 2*r ; c++)
{
if(c==1 || c == 2*r - 1 || r == n )
  cout << "&";
else
  cout<< " " ;
}
cout<< endl;
}
getch();
}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.