Sunday, 5 October 2014

Write a C++ statement that do the following

Leave a Comment














Write a C++ statement that do the following:
  1. Input integer variable x with cin and >>
  2. Input integer variable y with cin and >>
  3. Initialize the variable i to 1.
  4. Initialize the variable power to 1.
  5. Multiply variable power by x assign the result to power.
  6. Increment variable y to 1.
  7. Test y to see if it is less than or equal to x.
  8. Out put integer variable power with cout and <<.

Solution


  1. cin >> x;
  2. cin >> y;
  3. i = 1;
  4. power = 1;
  5. power *= x;
  6. i++;
  7. if( i <= y )
  8. cout << power << endl; 
If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: