Signup/Sign In

C Program To Find Power Of A Number Using Recursion

Learn C language tutorial

Logic To Find The Power Of The Number Using Recursion:

  • In this program by getting the input from the user in two forms a base number and exponent number,
  • The base number is multiplied by the number of times of the exponent number,
  • By using the if condition, the power of a number can be found, by multiplying the number by the number of times the exponent number is given and returns the value,

C PROGRAM TO FIND POWER OF THE NUMBER USING RECURSION:

#include <stdio.h>
 
long power (int, int);
 
int main()
{
    int exp, base;
    long value;
 
    printf("Enter The Number Base Number: ");
    scanf("%d", &base);
    printf("Enter The Exponent: ");
    scanf("%d", &exp);
    value = power(base, exp);
    printf("%d^%d is %ld", base, exp, value);
    return 0;
}
 
long power (int base, int exp)
{
    if (exp)
    {
        return (base * power(base, exp - 1));
    }
    return 1;
}

Output:

power



About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight