Power of N Number Program in C

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. int power(int,int);  
  4. void main()  
  5. {  
  6.  int n,p,result;  
  7.  clrscr();  
  8.  printf("Enter the number");  
  9.  scanf("%d",&n);  
  10.  printf("\nEnter the power to be calculated");  
  11.  scanf("%d",&p);  
  12.  result=power(n,p);  
  13.  printf("The result of %d to power %d is %d",n,p,result);  
  14.  getch();  
  15.  }  
  16. int power(int n,int p)  
  17. {  
  18.  static int r=1;  
  19.  if(p==0)  
  20.   {  
  21.     return(1);  
  22.     }  
  23.  else  
  24.   {  
  25.     r=r*n;  
  26.     power(n,p-1);  
  27.     }  
  28. return(r);