C++ PROGRAM
POWERS (using in-built function)
The code of this program will be shorter than the previous one (Powers I) because in this I will use the in built function, pow(a,b), to calculate powers.
This function is available in the header file: <math.h>.
This is even more useful because we can also find fractional powers of numbers such as
4^0.5, which is it's square root, i.e, 2.
Code:
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
double a,b;
cout<<"Powers"<<"\n";
cout<<"Enter any number: ";
cin>>a;
cout<<"Raised to power: ";
cin>>b;
cout<<"Ans. "<<pow(a,b);
getch();
}
Output:
First Run:
Second Run:
Third Run:
For any queries or suggestions please comment !
No comments:
Post a Comment