find power of a number in c
To find the power of a number in the C programming language, you can use the pow()
function from the math.h
library. Here is an example:
#include <stdio.h>
#include <math.h>
int main() {
double base, exponent, result;
printf("Enter the base number: ");
scanf("%lf", &base);
printf("Enter the exponent: ");
scanf("%lf", &exponent);
result = pow(base, exponent);
printf("%.2lf raised to the power of %.2lf is %.2lf\n", base, exponent, result);
return 0;
}
In this example, the pow()
function is used to calculate the result of raising the base
number to the power of the exponent
. The result is then printed to the console.
Please note that the pow()
function returns a double
value, so if you need an integer result, you may need to perform additional type casting or rounding.