Question #161133

Write a program that reads in a number and prints out the letter L using '*' characters

with each line in the L having width n. Further, the length of the horizontal bar should be

4n, and that of the vertical bar (i.e. not including the portion overlapping with the

horizontal bar) should be 3n. Thus for n=3 your program should print


***

***

***

***

***

***

***

***

***

************

************

************



Expert's answer

#include <iostream>

int main()
{
    int number;
    std::cout << "Please enter a number: ";
    std::cin >> number;

    if(!std::cin || number < 1)
    {
        std::cout << "Bad input\n";
        return 1;
    }

    for(int i = 0; i < 3 * number; ++i)
    {
        for(int j = 0; j < number; ++j)
        {
            std::cout << "*";
        }

        std::cout << "\n";
    }

    for(int i = 0; i < number; ++i)
    {
        for(int j = 0; j < 4 * number; ++j)
        {
            std::cout << "*";
        }

        std::cout << "\n";
    }
    
    return 0;    
}
LATEST TUTORIALS
APPROVED BY CLIENTS