oid pypart(int n){ // outer loop to handle number of rows // n in this case for (int i=0; i { // inner loop to handle number of columns // values changing acc. to outer loop for(int j=0; j<=i; j++ ) { // printing stars cout << "* "; } // ending line after each row cout << endl;}// Driver Functionint main(){ int n = 5; pypart(n); return 0;} |
Output:
* * * * * * * * * * * * * * *
// Function to demonstrate printing patternvoid pypart2(int n){ // number of spaces int k = n; // outer loop to handle number of rows // n in this case for (int i=0; i { // inner loop to handle number spaces // values changing acc. to requirement for (int j=0; j cout <<" "; // decrementing k after each loop k--; // inner loop to handle number of columns // values changing acc. to outer loop for (int j=0; j<=i; j++ ) { // printing stars cout << "* "; } // ending line after each row cout << endl; }}// Driver Functionint main(){ int n = 5; pypart2(n); return 0;} |
Output:
*
* *
* * *
* * * *
* * * * *
No comments:
Post a Comment