Write nested loops to print a rectangle. Sample output for given program
Write nested loops to print a rectangle. sample output for given program: * * * * * *.
A demo of the output for the given program is mentioned below;
* * *
* * *
C++ Program to Write nested loops to print a rectangle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> #include <conio.h> using namespace std; int main() { int StarRows,StarColumns,i,j; StarRows=2; StarColumns=3; //Takes input from user for StarColumns for(i=1; i<=StarRows; i++){//outer for loop for (j=1; j<=StarColumns; j++){//inner for loop cout<<"*";//print star } cout<<"\n";//move to next line } getch(); return 0; } |
Output
* * *
* * *
C++ Program to Write nested loops to print a rectangle by asking the user
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> #include <conio.h> using namespace std ; int main() { int StarRows,StarColumns,i,j; cout<<"Please Enter the number of StarRows: "; cin>>StarRows; //Takes input from user for StarRows cout<<"Please Enter the number of StarColumns: "; cin>>StarColumns; //Takes input from user for StarColumns for(i=1; i<=StarRows; i++){//outer for loop for (j=1; j<=StarColumns; j++){//inner for loop cout<<"*";//print star } cout<<"\n";//move to next line } getch(); return 0; } |
Output
Please Enter the number of StarRows:
2
Please Enter the number of StarColumns:
3
* * *
* * *