Ésta función la hice como una alternativa a pow(); de math.h.

Código: Seleccionar todo

double potencia(double base,double exponente)
{
    double temp = 1;
    int i = 0;
 
    for(i;i<exponente;i++)
        temp *= base; /* Es igual a temp = temp * base; */
 
    return temp;
}
--

Ejemplo de uso:

Código: Seleccionar todo

/* 
 * File:   main.cpp
 * Author: windhack
 *
 * Created on 11 de julio de 2010, 11:32 PM
 */

#include <iostream>

using namespace std;


double potencia(double base,double exponente);

int main()
{
    double base,exponente;
    cout << " === Potencia === " << endl;
    cout << "Introduce la base: " << endl;
    cin >> base;
    cout << "Introduce el exponente: " << endl;
    cin >> exponente;
    cout << "La potencia es: " << potencia(base,exponente) << endl;
    return 0;
}

double potencia(double base,double exponente)
{
    double temp = 1;
    int i = 0;
 
    for(i;i<exponente;i++)
        temp *= base;
 
    return temp;
}
Más Información: [Enlace externo eliminado para invitados]
Imagen

Imagen

Imagen

"The only thing they can't take from us are our minds."
Responder

Volver a “Otros lenguajes”