Here's a C program to find power of a number using pow() Function. This pow() function is not available to use by default, you first have to include the Math.H Header File to use this function.
# include <stdio.h> # include <conio.h> # include <math.h> void main() { int x, n, power; clrscr() ; printf("Enter the value of x : ") ; scanf("%d", &x) ; printf("\nEnter the value of n : ") ; scanf("%d", &n) ; power = pow(x, n); //This will calculate x ^ n printf("\nThe power of %d^%d is : %d", x, n, power) ; getch() ; }
Output of above program is
Enter the value of x : 2
Enter the value of n : 4
The power of 2^4 is : 16
Also look at: Program to calculate power without using pow() function. This program uses while loop to calculate the power. C Program to Find Power of a Number using While Loop
What is double?
It is a Double precision floating point number of size 8 bytes. Being larger in size than FLOAT, DOUBLE can store floating point values with great level of precision.
Hi Tanmay,
Brilliant article, glad I slogged through the C Program to Find Power of a Number using pow () Function it seems that a whole lot of the details really come back to from my past project.
why is saying c programming is a based-on java?
Even though there is no limit to the number of levels of nested include files you can have, your compiler might run out of stack space while trying to include an inordinately high number of files. This number varies according to your hardware configuration and possibly your compiler.
Very useful article, if I run into challenges along the way, I will share them here.
Obrigado,
Lee