Answer to Question #161117 in C++ for Naveen

Question #161117

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


***

***

***

***

***

***

***

***

***

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

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

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



1
Expert's answer
2021-02-05T10:28:14-0500
#include <iostream>
#include <string>

int main()
{
    std::cout << "Input positive number: ";

    int n;
    std::cin >> n;

    if(!std::cin || n < 1)
    {
        std::cout << "Error: expected positive number\n";
        return 1;
    }

    for(int i = 0; i < 3 * n; ++i)
    {
        std::cout << std::string(n, '*') << "\n";
    }

    for(int i = 0; i < n; ++i)
    {
        std::cout << std::string(4 * n, '*') << "\n";
    }
    
    return 0;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog