Average 3 numbers using integer arithmetic. - C++ Data Type

C++ examples for Data Type:int

Description

Average 3 numbers using integer arithmetic.

Demo Code

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

int main(int nNumberofArgs, char* pszArgs[])
{
    int nValue1;//  w w w .j a v  a 2  s  . c o  m
    int nValue2;
    int nValue3;

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

    cout << "n1 - ";
    cin  >> nValue1;

    cout << "n2 - ";
    cin  >> nValue2;

    cout << "n3 - ";
    cin  >> nValue3;

    cout << "n1/3 + n2/3 + n3/3 = " << nValue1/3 + nValue2/3 + nValue3/3 << "\n";

    // now the ratio of three sums
    cout << "(n1 + n2 + n3)/3   = " << (nValue1 + nValue2 + nValue3) / 3 << "\n";

    return 0;
}

Result


Related Tutorials