Table of Contents
In this article, we will discuss the Program to Print solid square star pattern in C++ programming language
In this post, we are going to learn How to write a program to print solid square star pattern in C++ language using for loop, while loop and Do-while loop
Program 1
This program allows the user to enter the size and then it will display solid square star pattern using for loop in C++ programming language
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,size; cout << "Please enter the size" << endl; cin>>size;//Takes input from the user for size for(i=1; i<=size; i++){ for(j=1; j<=size; j++){ cout<<"*"; } cout<<"\n"; } getch(); return 0; }
When the above code is executed it produces the following output
Approach
Program 2
This program allows the user to enter the size and then it will display solid square star pattern using while loop in C++ programming language
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,size; cout << "Please enter the size" << endl; cin>>size;//Takes input from the user for size i=1; while(i<=size){ j=1; while(j<=size){ cout<<"*"; j++; } cout<<"\n"; i++; } getch(); return 0; }
When the above code is executed it produces the following output
Approach
Program 3
This program allows the user to enter the size and then it will display solid square star pattern using do-while loop in C++ programming language
#include <iostream> #include <conio.h> using namespace std; int main() { int i,j,size; cout << "Please enter the size" << endl; cin>>size;//Takes input from the user for size i=1; do{ j=1; do{ cout<<"*"; j++; }while(j<=size); cout<<"\n"; i++; } while(i<=size); getch(); return 0; }
When the above code is executed it produces the following output
Approach
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.