Average 3 numbers using floating point arithmetic. - C++ Data Type

C++ examples for Data Type:float

Description

Average 3 numbers using floating point arithmetic.

Demo Code

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    float fValue1;
    float fValue2;
    float fValue3;

    cout << "Enter three floats:\n";

    cout << "f1 - ";
    cin  >> fValue1;/*from w ww . ja v  a2s .co  m*/

    cout << "f2 - ";
    cin  >> fValue2;

    cout << "f3 - ";
    cin  >> fValue3;

    cout << "n1/3 + n2/3 + n3/3 = " << fValue1/3 + fValue2/3 + fValue3/3 << "\n";

    // now the ratio of three sums
    cout << "(n1 + n2 + n3)/3   = " << (fValue1 + fValue2 + fValue3) / 3 << "\n";

    return 0;
}

Result


Related Tutorials