// power.cpp: compute the power of an integer #include #include using namespace std; const int base=3; unsigned long long power1(unsigned long); unsigned long long power2(unsigned long); int main(int argc, char* argv[]) { if (argc != 3) return 0; int algo = atoi(argv[1]); unsigned long long (*power)(unsigned long); switch (algo) { case 1: power = &power1; break; case 2: power = &power2; break; default: return 0; } stringstream ss(argv[2]); unsigned long n; ss >> n; cout << base << "^" << n << " = " << power(n) << endl; return 0; } /** * ----------------------------------------------------------------------- * a straightforward algorihtm for computing base^n * ----------------------------------------------------------------------- */ unsigned long long power1(unsigned long n) { unsigned long i; unsigned long long ret=1; for (unsigned long i=0; i