C++ Exercises: Print a square pattern with # character
C++ For Loop: Exercise-17 with Solution
Write a program in C++ to print a square pattern with # character.
Pictorial Presentation:
Sample Solution :-
C++ Code :
#include <iostream>
using namespace std;
int main()
{
int size;
cout << "\n\n Print a pattern like square with # character:\n";
cout << "--------------------------------------------------\n";
cout << " Input the number of characters for a side: ";
cin >> size;
for (int row = 1; row <= size; ++row)
{
for (int col = 1; col <= size; ++col)
{
cout << "# ";
}
cout << endl;
}
return 0;
}
Sample Output:
Print a pattern like square with # character: -------------------------------------------------- Input the number of characters for a side: 4 # # # # # # # # # # # # # # # #
Flowchart:
C++ Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C++ to list non-prime numbers from 1 to an upperbound.
Next: Write a program in C++ to display the cube of the number upto given an integer.
What is the difficulty level of this exercise?