x raised to the power of y
C program to find x raised to the power of y.
Program
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
double num1, num2, power;
printf("Enter first number: ");
scanf("%lf",&num1);
printf("Enter second number: ");
scanf("%lf",&num2);
power = pow(num1,num2);
printf("\n%lf raised to the power of %lf is: %lf",num1,num2,power);
getch();
}
Output
Enter first number: 4
Enter second number: 5
4.000000 raised to the power of 5.000000 is: 1024.000000
Explanation
In C, pow() function is used to find the power of any number. It is a library function of math.h header file.
Syntax for pow() function in C is as follows,
In the above program, this function is used to find the power of a number.
For this, base value and exponent value are entered by the user, and received in variables 'num1' and 'num2' respectively. Power of a number is calculated using statement
and the result is stored in 'power' variable.
Note that %lf is the format specifier for double data type.
Syntax for pow() function in C is as follows,
double pow (double base, double exponent);
In the above program, this function is used to find the power of a number.
For this, base value and exponent value are entered by the user, and received in variables 'num1' and 'num2' respectively. Power of a number is calculated using statement
pow(num1, num2)
and the result is stored in 'power' variable.
Note that %lf is the format specifier for double data type.