/************************************************
** In this example, I'm simply trying to
** compute 8768767 / 3^5 ... but I get different
** answers in the two different ways I call pow.
** Explain what's going on?
************************************************/
#include <iostream>
#include <cmath>
using namespace std;
int pow(int x, int k);
int main()
{
int b = 8768767;
//-- FIRST EXAMPLE CALLING POW ----------------//
double z = 3.0, t = 5.0;
cout << "1st answer is " << b / pow(z,t) << endl;
//-- SECOND EXAMPLE CALLING POW ---------------//
int a = 3, e = 5;
cout << "2nd answer is " << b / pow(a,e) << endl;
return 0;
}
int pow(int x, int k)
{
int ans = 1;
for(int i = 0; i < k; i++)
ans = ans * x;
return ans;
}