Q:

Write a program in C++ to display the pattern like a pyramid using asterisk and each row contain an odd number of asterisks

0

Write a program in C++ to display the pattern like a pyramid using asterisk and each row contain an odd number of asterisks

Sample Output:

 Display such a pattern like a pyramid containing odd number of asterisk in each row:                                                         
-----------------------------------------------------------------------------------------                                                     
 Input number of rows: 5                                               
                                                                       
    *                                                                  
   ***                                                                 
  *****                                                                
 *******

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;

int main()
{
   int i,j,n;
    cout << "\n\n Display such a pattern like a pyramid containing odd number of asterisk in each row:\n";
    cout << "-----------------------------------------------------------------------------------------\n";
    cout << " Input number of rows: ";
    cin >> n;
  for(i=0;i<n;i++)
   {
     for(j=1;j<=n-i;j++)
     cout<<" ";
     for(j=1;j<=2*i-1;j++)
       cout<<"*";
     cout<<endl;
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now