gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
write a c++Write a C++ Program to print the letter Y and H using stars. Note: 1) Using…
- User
write a c++Write a C++ Program to print the letter Y and H using stars. Note:
- Using nested For Loop
- The number of lines is given by user.
- Using one Outer loop to print my letters.
- Print the letters beside each other.
- Assistant
#include using namespace std;
int main() { int lines; cout << "Enter the number of lines: "; cin >> lines;
for(int i=0; i<lines; i++) { // Print the letter Y // First half of the letter Y for(int j=0; j<i; j++) { cout << " "; } cout << ""; for(int j=i+1; j<lines; j++) { cout << " "; } for(int j=i+1; j<lines; j++) { cout << " "; } cout << ""; cout << endl;
// Second half of the letter Y for(int j=0; j<=i; j++) { cout << " "; } cout << "*"; for (int j=i+1; j<lines; j++) { cout << " "; } for(int j=i+1; j<lines; j++) { cout << " "; } cout << "*"; cout << endl; // Print the letter H for(int j=0; j<=i; j++) { cout << "*"; for(int k=0; k<lines-i-1; k++) { cout << " "; } cout << "*"; for(int k=0; k<i; k++) { cout << " "; } cout << "*"; for(int k=0; k<lines-i-1; k++) { cout << " "; } cout << "*"; cout << endl; }}
return 0; }