home Sandy, UT
Tuesday, 2017.11.21
10:39 MDT [GMT-7]
Brionews - Company Logo Condition: Partly Cloudy
Temperature: 9.9°C (49.8°F)
Barometer: 1028 mb and rising
IT
MIX
News
Low Cost Affordable C C++ PHP mySQL Perl Programs Development
Assignment for C++ class.
Very simple: write a routine to raise a number to an exponent
Download the executable: pow.exe
June 11, 2004

Raising a Number to a Power

/**
  *  @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';
}

2004.06.11

Vincenzo Maggio