67 279
Assignments Done
99,1%
Successfully Done
In November 2018

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
Expert's answer
# 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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions