Answer to Question #4918 in C++ for salma

Question #4918
Write a program to read two integers x and y then to calculate x to the power y by using while statement
1
Expert's answer
2011-10-28T10:45:21-0400
# include <iostream>

using namespace std;

int main()
{
int x, y = 0, i = 0,c = 1;
cout<<"Enter x(number): ";
cin>>x;
cout<<"Enter y(power): ";
cin>>y;
if (x == 0 && y == 0)
& cout<<"Nondefinable notion"<<endl;

else if (y >= 0)
{
while (y != 0 )
{
& c=c*x;
& y--;
&
}
cout<<"x^y = "<<c<<endl;
}
else//y<0
{
& while (y != 0 )
{
&
& c=c*x;
& y++;
&
}
& cout<<"x^y: "<<(double)1/c<<endl;
}


system("PAUSE");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS