Wednesday, March 20, 2013

Program to calculate x to the power n using power function of math.h

A simple program to calculate power of a given number.
We have an inbuilt power() function in math.h. This function takes two arguments.
Example:

temp=power(num,pow);

In above example the power() function is taking two arguments. First argument is a number and second one is power() for that number. So this function will return num to the power pow. We are using a temporary variable to hold the result because power() function returns a value.
We can use inbuilt math.h functions for basic mathematical calculations. For example we can use sqrt() function to get square root of a number. ceil(), floor(), log() and many other trigonometric functions are already declared in math.h header file.

This complete program will explain the how power() function really works-

Powered by Blogger.