|
Salt Lake City Wednesday, 2013.06.19 03:57 MDT [GMT-7] |
![]() |
Condition: Mostly Clear Temperature: 26°C/78.1°F Barometer: 1007.8 mb and falling |
| IT | |
|---|---|
| MIX | |
| News |
/**
* @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