WAP 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. [Write the above program in two ways:- -using function overloading. -using default arguments.]
#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;
}
Comments
Leave a comment