xxxxxxxxxx
#include <stdio.h>
double power(double base, int exponent) {
double result = 1.0;
if (exponent >= 0) {
for (int i = 0; i < exponent; ++i) {
result *= base;
}
} else {
for (int i = 0; i > exponent; --i) {
result /= base;
}
}
return result;
}
int main() {
double base = 2.0;
int exponent = 3;
double result = power(base, exponent);
printf("%.2f ^ %d = %.2f\n", base, exponent, result);
return 0;
}
xxxxxxxxxx
#include <stdio.h>
#include <math.h>
int main()
{
double base, power, result;
printf("Enter the base number: ");
scanf("%lf", &base);
printf("Enter the power raised: ");
scanf("%lf",&power);
result = pow(base,power);
printf("%.1lf^%.1lf = %.2lf", base, power, result);
return 0;
}
xxxxxxxxxx
#include <math.h>
double pow(double x, double y);
float powf(float x, float y);
long double powl(long double x, long double y);
xxxxxxxxxx
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.