Please give the c++ code for following problems.

1) Write a C++ program to calculate x raised to the y power. The program should have a while repetition control structure.solved

2) Print the integers form 1 to 20 using a while loop and the counter variable x. Assume that the variable x has been declared, but not initialized. Print only 5 integers per line. Hint: Use the calculation x%5. When the value of this is 0, print a newline character, otherwise print a tab character.

Last edited on
I'll help you write that if you'd like but I'm not doing your assignment for you because that won't help you at all. Make a stab at the code, post it here and we'll dutifully give you help but you get nowhere in life just asking for it to be done for you.
Just because I'm an ass. Here is your code:
 ``123456789101112`` ``````// Number 1 #include #include int main() { int x, y; std::cout << "Enter X: "; std::cin >> x; std::cout << "Enter Y: "; std::cin >> y; while (true) std::cout << "X^Y = " << pow(x,y) << "\n"; return 0; }``````

 ``12345678`` ``````// Number 2 #include int main() { while (true) std::cout << "12345\n678910\n1112131415\n1617181920\n"; return 0; }``````
@ volatile tx, but your both program gives continuous loop...

finally I got the answer which work perfectly.
 ``1234567891011121314151617181920212223`` ``````#include using namespace std; int main() { int x, y, i, power; i = 1; power = 1; cout << "Enter x: "; cin >> x; cout << "Enter y: "; cin >> y; while ( i <= y ) { // to multiply the x itself to the no. of y power = power * x; i++; } cout << "x to the power y is: " << power << endl; return 0; }``````

 ``123456789101112131415161718192021222324`` ``````#include using namespace std; int main() { int x = 0; while(x <= 20) { if(x % 5 == 0 && x != 0) { cout << " " << x << endl; } else if((x % 5 == 1 || x == 0) && x != 1) { cout << x; } else { cout << " " << x; } x++; } }``````
 ``12345678910111213141516171819202122`` ``````#include using namespace std; int main() { int x; x = 1; while ( x <= 20 ) { cout << x; if ( x % 5 == 0 ) cout << "\n"; else cout << "\t"; x++; } return 0; }``````