Answer to Question #161023 in C++ for Naveen

Question #161023

Write a program that reads in a number n and prints out asterisks(‘*’) in the shape of a

rectangle having n rows and 2*n columns. Thus for n=3 your program should print


******

******

******


1
Expert's answer
2021-02-03T11:18:27-0500
#include <iostream>

int main() {

    int n;

    std::cout << "Enter number of asterisks:";
    std::cin >> n;

    for (int i = 0; i < n; i++) {

        for (int j = 0; j < n*2; ++j) {
            std::cout << "*";
        }

        if (i != n - 1) std::cout << "\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

Naveen
03.02.21, 19:20

*****Excellent work *****

Leave a comment

LATEST TUTORIALS
New on Blog