![]() |
Salt Lake City Monday, 2008.09.08 08:48 MST [GMT-7] |
| Home - IT: IT Security - Programming - OS - HW - SW - Internet - IT News - Technology - Science - Communication - News: World - USA - USA States - Alternative - Business - Investment - more coming soon... | |
/**
* @title: power.cpp
* @date: 2004.06.11
* @author: vinnie */
#include <iostream>
#include <stdlib.h>
using namespace std;
long power( int base, int exp)
{
long acc = 1;
for ( ; exp; exp-- )
acc *= (long) base;
return acc;
}
void main()
{ int base, exp;
cout << "Raising a number to a power.\nInsert 2 numbers, \
first the base, Enter, then the Exponent: ";
cin >> base;
cout << "Good job! Now the Exponent: ";
cin >> exp;
cout << base << "^" << exp << " = " << power(base, exp) << '\n';
}
Vincenzo Maggio