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 the # 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?
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join