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

12 comments:

  1. thank u very much

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

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

    ReplyDelete
  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.

    ReplyDelete
  5. 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;
    }

    ReplyDelete
  6. 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

    ReplyDelete
  7. 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));

    }

    ReplyDelete
  8. #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);
    }
    }


    ReplyDelete
  9. Thanks for the post really helpful i have done it in another please have a look http://ioeengineer.blogspot.com/2014/02/write-program-to-find-x-to-power-of-y.html

    ReplyDelete