C program to find power of a number using pow function
Write a C program to input any two numbers x and y from user and find power of both number i.e. x^y using inbuilt library pow() function.
Example:
Input number 1: 5
Input power number 2: 2
Output x^y = 25
Enjoy it..............
Input number 1: 5
Input power number 2: 2
Output x^y = 25
Required knowledge
Fundamentals of C, Data types, Taking user input in CProgram to find power of a number
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| /** * C program to find power of any number */ #include <stdio.h> #include <math.h> //Used for pow() function
void
main() { double x, y, power; // Reads two numbers from user to calculate power printf ( "Enter any two number x and y : " ); scanf ( "%lf%lf" , &x, &y); // Calculates x^y power = pow (x, y); //Power function already define in lib math.h printf ( "x^y = %.0lf" , power); } |
Output
Enter any two number x and y : 5
2
x^y = 25
2
x^y = 25
Note: %.0lf is used to print fractional values up to 0 decimal places. You can also use %lf to print fractional values normally up to six decimal places.
Enjoy it..............
Comments
Post a Comment
Dears! Yours Comment approved in 24 hours also your answer in 24 hours.......