power of in c code example
Example 1: c code to find power of a number
#include <stdio.h>
int main() {
int base, exp;
long double result = 1.0;
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exp);
while (exp != 0) {
result *= base;
--exp;
}
printf("Answer = %.0Lf", result);
return 0;
}
Example 2: power func in c
The function pow() is used to calculate the power raised
to the base value. It takes two arguments. It returns the
power raised to the base value. It is declared in
“math.h” header file.