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 

Required knowledge

Fundamentals of CData typesTaking user input in C 

Program 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

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

Popular posts from this blog

C program to calculate velocity

C program to find square root of a number

C program to find maximum between two numbers