|
Salt Lake City Saturday, 2012.02.04 10:54 MDT [GMT-7] |
![]() |
Condition: Rain Temperature: 1°C/34.3°F Barometer: 1025.4 mb and steady |
| 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