We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents fdbb728 + dbd9eb5 commit 4a71ab7Copy full SHA for 4a71ab7
Divide and Conquer/Powerofnumber.cpp
@@ -0,0 +1,34 @@
1
+
2
+#include <iostream>
3
4
+using namespace std;
5
+int powerofnumber(int a,int n)
6
+{int mid=0,c=0,b=0;
7
+ if(n==1)
8
+ {
9
+ return a;
10
+ }
11
+ else
12
13
+ mid=n/2;
14
+ b=powerofnumber(a,mid);
15
+ c=b*b;
16
+ if(n%2==0)
17
18
+ return c;
19
20
21
22
+ return a*c;
23
24
25
+}
26
+int main()
27
+{ int num=0,ans=0,power=0;
28
+ cout<<"Power of n element\n";
29
+ cout<<"\nEnter the Number\t=\t";cin>>num;
30
+ cout<<"Enter the power\t=\t";cin>>power;
31
+ ans= powerofnumber(num,power);
32
+ cout<<"Answer\t=\t"<<ans;
33
+ return 0;
34
0 commit comments