Skip to content

Instantly share code, notes, and snippets.

@ebba0194
Created December 11, 2017 04:46
Show Gist options
  • Save ebba0194/397952f2e7b5304f5d778725fd8c7225 to your computer and use it in GitHub Desktop.
Save ebba0194/397952f2e7b5304f5d778725fd8c7225 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void printRow (int, int);
int main()
{
int nrows;
cout<<"Enter number of rows (>0): ";
cin>>nrows;
while (nrows < 0){
cout<<"Invalid entry - try again! \nEnter a positive integer: ";
cin>>nrows;
}
for( int r = 1 ; r <= nrows ; r++ ) {
printRow( r, nrows ) ;
}
return (0);
}
void printRow( int r, int nrows )
{
int stars = r*2 - 1 ;
int blanks = nrows - r ;
for( int i = 0 ; i < blanks ; i++ ){
cout << " " ;
}
for( int i = 0 ; i < stars ; i++ ){
cout << "*" ;
}
cout << endl ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment