Answers for "c code to calculate power using recursion"

0

c code to calculate power using recursion

#include <stdio.h>
int power(int n1, int n2);
int main() {
    int base, a, result;
    printf("Enter base number: ");
    scanf("%d", &base);
    printf("Enter power number(positive integer): ");
    scanf("%d", &a);
    result = power(base, a);
    printf("%d^%d = %d", base, a, result);
    return 0;
}

int power(int base, int a) {
    if (a != 0)
        return (base * power(base, a - 1));
    else
        return 1;
}
Posted by: Guest on May-29-2021

Code answers related to "c code to calculate power using recursion"

Browse Popular Code Answers by Language