pages

Tuesday, 13 April 2021

c-program to calculate the power using recursion.| c programming

 program to calculate the number by entering the base and power of a number by recursive function 

In this program, we are will now calculating the  power of the number by taking input base and power of the number by the user 

if the exponent is 0 ,then power is 1. this is the base condition of our recursive function. 

In this program ,the function fun() is recursive function. if the power of the number is zero ,then the function return 1.

if the power not 0 then , the function recursively call itself .

#include<stdio.h>
#include<conio.h>
void main()
{
   int b,p;
   printf("enter the base of the number\n");
   scanf("%d",&b);
   printf("enter the power of the number\n");
   scanf("%d",&p);
   printf("the number is %d",fun(b,p));
   getch();
}
int fun(int a,int b)
{
   if(b!=0)
         return(a*fun(a,b-1));
   else
         return(1);
}

output:
     






















1 comment: