Question #102721

Write a program that reads in a number and prints out the letter T using '*' characters with each line in the T having width n. Further, the length of the horizontal bar should be 3n, and that of the vertical bar 2n. Thus for n=3 your program should print


*********

*********

*********

***

***

***

***

***

***

Expert's answer

#include <iostream>
using namespace std;

int main()
{
    int n;

    cin >> n;
    for (int i = 0; i < n; i++)
        cout << string(n * 3, '*') << endl;
    for (int i = 0; i < 2 * n; i++)
        cout << string(n, ' ') << string(n, '*') << endl;
    return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS