pow() Function : C Reference
Calculating x^n Using Pow function :
#include<stdio.h> #include<math.h> int main() { int num,power,result; printf("\nEnter the numaber and its Power : "); scanf("%d%d",&num,&power); result = pow(num,power); printf("\nResult : %d",result); return(0); }
Output :
Enter the numaber and its Power : 6 2 Result : 36
Explanation of the Code :
- In a C Programming Language we can find the expression of type “x raise to y”.
- Power function is used to find the square , cube of number or number raise to any index.
- math.h header file contain the power function.
Syntax of the Pow Function :
pow(num1,num2);
represents num1 raise to num2.
Different Ways of Using Power Function :
Way 1 : Used to Find Cube
result = pow(num,3);
Way 2 : Used to Find Square
result = pow(num,2);