#include <iostream>
using namespace std;
int main() {
cout<<"Program To Form A Square"<<endl<<endl;
cout<<"* * * * * *"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"* * * * * *"<<endl;
return 0;
}
Output:Working Of The Program:
1. The code starts with the inclusion of the "iostream" header file, which is necessary to use the standard input/output stream objects like "cout" and "cin" in C++.
2. The "using namespace std" statement is used to avoid typing "std::" before standard library objects like "cout" and "endl".
3. The "main" function is the starting point of the program, and it's where the execution begins.
4. The first line inside the "main" function prints a string message to the console using the "cout" object.
5. The next six lines print a square shape made of asterisks and spaces to the console. The first and last lines contain six asterisks separated by spaces, forming the top and bottom sides of the square. The middle four lines contain an asterisk followed by four spaces and another asterisk, forming the left and right sides of the square.
6. Finally, the "return 0" statement is used to indicate a successful termination of the program.
2. The "using namespace std" statement is used to avoid typing "std::" before standard library objects like "cout" and "endl".
3. The "main" function is the starting point of the program, and it's where the execution begins.
4. The first line inside the "main" function prints a string message to the console using the "cout" object.
5. The next six lines print a square shape made of asterisks and spaces to the console. The first and last lines contain six asterisks separated by spaces, forming the top and bottom sides of the square. The middle four lines contain an asterisk followed by four spaces and another asterisk, forming the left and right sides of the square.
6. Finally, the "return 0" statement is used to indicate a successful termination of the program.
No comments:
Post a Comment