Monday 7 April 2014

C++ programme to print pattern / pyramid

#include <iostream>
using namespace std;
int main()
{
int i, j, n, k,l;
cout << "enter the n/column height :";
cin >> n;
for (i = 0; i < n; i++)
{

for (l =0 ; l < n - i - 1; l++)
{
cout << " ";
}

for (j =0 ; j < 2 * i - 1; j++)
{
cout << "#";

}
//for (k = 0; k< i - 1; k++)
//{ cout << " "; }

cout << endl;
}

return 0;
}

enter the n/column height :15

             #
            ###
           #####
          #######
         #########
        ###########
       #############
      ###############
     #################
    ###################
   #####################
  #######################
 #########################
###########################
Press any key to continue . . .

No comments:

Post a Comment