[ create a new paste ] login | about

Link: http://codepad.org/3gHUYVtK    [ raw code | output | fork ]

vicenaf - C++, pasted on Sep 6:
#include <iostream>

using namespace std;


void valor_absoluto (float a);

int main()
{
    float dato_teclado;
    cout << "Introduce un valor y calculare el valor absoluto: " << endl;
    cin >> dato_teclado;

    valor_absoluto(dato_teclado);

    cout << "\nEl valor de dato_teclado es: " << dato_teclado;

    return 0;
}


void valor_absoluto (float a)
{
    if (a < 0) a = a * (-1); // a = -a // a = 0 - a

    cout << "\nEl valor absoluto es: " << a;
}


Output:
1
2
3
4
Introduce un valor y calculare el valor absoluto: 

El valor absoluto es: 1.41889
El valor de dato_teclado es: -1.41889


Create a new paste based on this one


Comments: