FIND POWER OF A NUMBER USING RECURSION USING C PROGRAM

Find power of a number using recursion using c program

#include<stdio.h>
int main(){
int pow,num;
long int res;
long int power(int,int);
printf("\nEnter a number: ");
scanf("%d",&num);
printf("\nEnter power: ");
scanf("%d",&pow);
res=power(num,pow);
printf("\n%d to the power %d is: %ld",num,pow,res);
return 0;
}
int i=1;
long int sum=1;
long int power(int num,int pow){
if(i<=pow){
sum=sum*num;
power(num,pow-1);
}
else
return sum;
}

Sum of n numbers using recursion in c
Matrix multiplication using recursion in c
Multiplication using recursion in c
Lcm using recursion in c
Using recursion in c find the largest element in an array
Prime number program in c using recursion
Decimal to binary conversion in c using recursion
C program for fibonacci series using recursion
Reverse a string using recursion
Write a program for palindrome using recursion
Find factorial of a number using recursion in c program
Find gcd of a number using recursion in c program
Find sum of digits of a number using recursion using cprogram
Find power of a number using recursion using c program
Binary search through recurssion using c program
Reverse a number using recursion in c program
Big list of c program examples

1. thank u very much

2. it does not works for power(10,6)...why?

3. it's working for (10,6) also once check it....

4. can you help me with this one? program that will print out

powers of 2: 1, 2, 4, 8, .. up to 2n, where n is a user input.

1. (i=1;i<=Thenumberyouinput;i++);

try it

5. It Does n't work

6. this power function is not efficient...
modify like this>>>>>>>
A better recursion function for power calculation...
pow(int a,int b)
{
if(b==0)
return 1;
if(b%2==0)
return pow(a*a,b/2);
return pow(a*a,b/2)*a;
}

7. good job

8. Yr what is this? It is not working. Make it right, otherwise my girlfriend will kill me. do it fast. Tomorrow will b her practicals, I am management student. Did not know what the hell are you doing with this C

9. try this ....this code surely works :) chancahl tripathi:)
#include
#include
int power(int x,int p);
void main()
{
int n,p;
clrscr();
printf("enter no.and power");
scanf("%d%d",&n,&p);
printf("%d",power(n,p));
getch();
}
int power(int x,int p)
{
if(p==0)
return 1;
else
return (x*power(x,p-1));

}

10. #include
#include
#include
int power(int,int,int);
main()
{
int num,i=1,p,result;
printf("Enter a number:");
scanf("%d",&num);
printf("Enter power:");
scanf("%d",&p);
result=power(num,i,p);
printf("\n%d to the power of %d is: %d",num,p,result);
getch();
}
int power(int num,int i,int p)
{
if(i==p)
{
return pow(num,i);
}
else
{
return power(num,i+1,p);
}
}

11. #include
#include
unsigned int Number_a_to_number_b(unsigned int a, unsigned int b);
unsigned int x,y;
int main()
{
printf("Enter a base");
scanf("%u",&x );
printf("Enter a power");
scanf("%u",&y);
printf("%u to power %u is %u",x,y,answer);

return 0;
}
unsigned int Number_a_to_number_b(unsigned int a, unsigned int b)
{
if (b==0)
return 1;
if (b==1)
return a;

return a*Number_a_to_number_b(a,(b-1));

}

12. this program much better this
#include
int power(int a,int b);
main()
{
int a,out;
int b;
printf("Enter Power :");
scanf("%d",&a);
printf("Enter base");
scanf("%d",&b);
out= power(a,b);
printf("power=%d",out);
getch();
}
int power(int x, int y)
{
int i,t=1;
for(i=1;i<=y;i++)
{
t=t*x;
}
return t;
}