Answer to Question #228149 in C++ for Arup

Question #228149

Write a program which displays a given character, n number of times, using a function. When the n value is not provided, it should print the given character 80 times. When both the character and n value is not provided, it should print ‘*’ character 80 times.

 By using default arguments


1
Expert's answer
2021-08-21T02:45:39-0400
#include <iostream>

void printCharNTimes(char c = '*', int n = 80) {
    for (int i = 0; i < n; i++) {
        std::cout << c;
    }
    std::cout << std::endl;
}

int main() {
    printCharNTimes();
    printCharNTimes('+');
    printCharNTimes('-', 10);

    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
APPROVED BY CLIENTS