Created
December 11, 2017 04:46
-
-
Save ebba0194/397952f2e7b5304f5d778725fd8c7225 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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