C++ Examples – C++ program to display reverse pyramid.




In the lesson we will learn how to print pyramid of stars in reverse order Like shown below.

* * * * * * * * * * *
  * * * * * * * * *
    * * * * * * *
      * * * * *
        * * *
          *
#include <iostream>
using namespace std;
int main()
{
  int rows,i,j,space;
  cout<<"Enter number of rows: ";
  cin>>rows;
  for(i=rows;i>=1;--i)
  {
    for(space=0;space<rows-i;++space)
      cout<<"  ";
    for(j=i;j<=2*i-1;++j)
      cout<<"* ";
    for(j=0;j<i-1;++j)
      cout<<"* ";
    cout<<endl;
  }
  return 0;
}

/*
Enter number of rows: 6
* * * * * * * * * * *
  * * * * * * * * *
    * * * * * * *
      * * * * *
        * * *
          *

*/

After you write a C++ program you compile it; that is, you run a program called compiler that checks whether the program follows the C++ syntax

  • if it finds errors, it lists them
  • If there are no errors, it translates the C++ program into a program in machine language which you can execute

 

 

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*