ahmed0saber

Calculate powers of a number in C++

Nov 4th, 2020
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.25 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int a , b , r=1;
  6.     cout << "Enter a number (a)" << endl;
  7.     cin >> a;
  8.     cout << "Enter its power (b)" << endl;
  9.     cin >> b;
  10.     while (b>0)
  11.     {
  12.         b=b-1;
  13.         r=r*a;
  14.     }
  15.     cout << endl << "a^b = " << r;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment