Read three double-precision, floating-point numbers and passes them to a function to get the smallest number. - C++ Data Type

C++ examples for Data Type:double

Description

Read three double-precision, floating-point numbers and passes them to a function to get the smallest number.

Demo Code

#include <iostream>

double minimum(double, double, double);

int main(int argc, const char *argv[]) {
    double d1, d2, d3;

    std::cout << "Enter three double values: ";
    std::cin >> d1 >> d2 >> d3;

    std::cout << "Smallest: " << minimum(d1, d2, d3) << std::endl;
    return 0;//from   www.ja va  2s .c  o  m
}
// finds and returns the smallest of 3 values
double minimum(double d1, double d2, double d3) {
    double minimum = d1;

    if (d2 < minimum) minimum = d2;

    return (d3 < minimum) ? d3 : minimum;
}

Result


Related Tutorials