Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  recursive power
Language: C/C++
Code:
#include <stdio.h>
int recpow(int);
int main()
{
    int n,result;
    printf("enter any number");
    scanf("%d",&n);
    result=recpow();
    printf("%d raised to power %d id = %d",n,n,result);
    retrun 0;
}
int recpow(int n)
{
    if(n==0)
     {
         printf("error occured");
         getch();
         exit(-1);
     }
     else
     {
         if(n==1)
           return 1;
         else
          {
              int p=1,i;
              for(i=n;i>1;i--)
                p=p*recpow(n);
              return p;
          }
     }
    return 0;
}     
          
Comments: