-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02.cpp
60 lines (46 loc) · 894 Bytes
/
02.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
void printName(){
static int cnt = 0;
if(cnt==5) return;
cout<<"Rushikesh\n";
cnt++;
printName();
}
void printN(int n){
static int cnt = 1;
if(cnt>n)return;
cout<<cnt<<" ";
cnt++;
printN(n);
}
void printOneToN(int n){
if(n<5)return;
cout<<n<<" ";
printOneToN(n--);
}
void printBackN(int n){
if(n<1)return;
printN(n--);
cout<<n<<" ";
}
int main(){
//* Q1 --> Print name 5 times
//printName();
//* Q2 --> Printing linearly from 1 to N
//int n;
//cout<<"Enter a number: ";
//cin>>n;
// printN(n);
//* Q3 --> Print n to 1
// int n;
// cout<<"Enter a number: ";
// cin>>n;
// printOneToN(n);
//* Q3 --> Print 1 to n using backtrack
int n;
cout<<"Enter a number: ";
cin>>n;
printBackN(n);
return 0;
}