-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA_34_Recursion_4.cpp
More file actions
56 lines (52 loc) · 1012 Bytes
/
Copy pathDSA_34_Recursion_4.cpp
File metadata and controls
56 lines (52 loc) · 1012 Bytes
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
#include<iostream>
using namespace std;
void reverse(string& str,int i,int j){
//base case
if(i>j)
return ;
swap(str[i],str[j]);
i++;
j--;
//Recursive call
reverse(str,i,j);
}
bool checkpallindrome(string s,int i,int j){
if(i>j)
return true;
if(s[i]!=s[j])
return false;
else{
return checkpallindrome(s,i+1,j-1);
}
}
int power(int a,int b){
if(b==0){
return 1;
}
if(b==1){
return a;
}
int ans=power(a,b/2);
if(b%2==0){
return ans*ans;
}
else{
return a*ans*ans;
}
}
int main(){
cout<<"Namastey Duniya \n"<<endl;
// string name="abba";
// reverse(name,0,name.length()-1);
// cout<<name<<endl;
// bool ispallindrome=checkpallindrome(name,0,name.length()-1);
// if(ispallindrome)
// cout<<"Pallindrome"<<endl;
// else
// cout<<"Not Pallindrome"<<endl;
int a,b;
cin>>a>>b;
int ans=power(a,b);
cout<<ans<<endl;
return 0;
}