Wednesday, 25 May 2016

Write a program to print the following output using loop: 

  

Solution: 
                 #include<iostream.h> 
                #include<conio.h> 
                void main()
                {
                      int row, pound, star; 
                      int nrows = 6; 
                      for(row = 1; row <= nrows; row++)
                      {
                           for(pound = 1; pound <= nrow-row; pound++)
                                 cout<<"#"; 
                           for(star =1; star <= 2*row-1; star++){
                               if(star == 1 || star == 2*row-1)
                                    cout<<"*"; 
                               else 
                                     cout<<"#"; 
                          for(pound = 1; pound <=  nrow-row; pound++)
                                cout<<"#"; 
                           cout<<endl;
                      }
                }
                  getch();
              }

No comments:

Post a Comment