Sunday 5 October 2014

Raised the power of x to y using while loop.

Leave a Comment

 Solution

#include<iostream>
using namespace std;

 int main()
 {
       // Variable declarations.
       int x, y, i, power;

   
       i = 1;
       power = 1;
 
       cout << "Enter base as an integer: ";
       cin >> x;
 
       cout << "Enter exponent as an integer: ";
       cin >> y;
 
       while( i <= y)
       {
             power *= x;
             ++i;
       }
 
       cout << power << endl;
system("pause");

 }

 Output


If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: