2011-10-28T09:41:47-04:00
Write a program to read two integers x and y then to calculate x to the power y by using while statement
1
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 !
Learn more about our help with Assignments:
C++
Comments