Exponentiation using multiplication

// Exponential using multiplication.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
using namespace std;
int exp (int b, int e)
{
       int result;
       result = 1;
       while (e != 0)
       {
             result *=b;
             e = e - 1;
       }
       return(result);
}
int _tmain(int argc, _TCHAR* argv[])
{
       int b, e;
       cout << "Enter base and exponent: ";
       cin >> b >> e;
       cout << b << " to the " << e << " = " << exp(b,e) << endl;
       system("pause");
       return 0;
}


Share on Google Plus