Skip to content

Commit 11a10b8

Browse files
committed
added-printnameNtimesUsingRec
1 parent 251a362 commit 11a10b8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: C++/printnameNtimes.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
void printName(int N, const std::string& name) {
5+
if (N > 0) {
6+
std::cout << name << std::endl;
7+
printName(N - 1, name);
8+
}
9+
}
10+
11+
int main() {
12+
int N;
13+
std::string name;
14+
15+
std::cout << "Enter your name: ";
16+
std::cin >> name;
17+
18+
std::cout << "Enter the number of times to print your name: ";
19+
std::cin >> N;
20+
21+
printName(N, name);
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)