Example :
22 = 4 which is same as 2 x 2 = 4
44 = 256 which is same as 4 x 4 x 4 x 4 = 256
Links that you may find important :
https://en.wikipedia.org/wiki/Nth_root
http://www.mathsisfun.com/numbers/nth-root.html
http://www.rkm.com.au/calculators/CALCULATOR-powers.html
http://www.free-online-calculator-use.com/exponent-calculator.html
Code :
#include <iostream.h>
#include <conio.h>
int power(int,int);
void main()
{
int no,pow,val;
clrscr();
cout<<"Enter number : ";
cin>>no;
cout<<"Enter the power : ";
cin>>pow;
val=power(no,pow);//called function power which returns integer
cout<<"The answer is : "<<val;
getch();
}
int power(int no, int pow)
{
int val;
val=no;
while(pow>=1)
{
if(pow==1)
return no;
if(pow>1)
val=val*no;
pow--;
}
}
Output :Enter number : 2 Enter the power : 8 The answer is : 256Note : Since the type of number is integer the range of number which it can calculate is restricted.
Note : Leave a comment if you feel the program is incorrect and/or has errors and/or if the program and its output don't match. Please report about broken links.
No comments:
Post a Comment