Write a program to print following lines of text in an exact format as,
*****************************************
** Welcone to C++ programming language **
*****************************************
here's a C++ program to print the desired output with explanation:
#include <iostream>
using namespace std;
int main() {
// Using escape sequences to print the asterisks and newlines
cout << "*****************************************\n";
cout << "** Welcome to C++ programming language **\n";
cout << "*****************************************\n";
return 0;
}
Output:
*****************************************
** Welcome to C++ programming language **
*****************************************
** Welcome to C++ programming language **
*****************************************
Explanation:
- The #include <iostream> directive is used to include the iostream library, which provides input/output functionality.
- The main() function is the entry point of the program, where the execution starts.
- The cout object is used to print each line of text, followed by a newline character (\n).
- We use escape sequences to print the asterisks (*) and newlines (\n) in the desired format.
- The first and last lines contain 41 asterisks each, while the second line has 2 asterisks at the beginning and end, and the text "Welcome to C++ programming language" in between.
- The program is written in C++, so the file should be saved with a .cpp extension and compiled and run using a C++ compiler and runtime.
No comments:
Post a Comment
If you have any doubts, please let me know