Read three integers, prints the sum, average, product, smallest and largest of these numbers. Use macros - C++ Language Basics

C++ examples for Language Basics:Console

Description

Read three integers, prints the sum, average, product, smallest and largest of these numbers. Use macros

Demo Code

#include <iostream>

#define MIN(a, b) ((a < b) ? a : b)//from ww w .ja  v a 2  s .  c  o m
#define MAX(a, b) ((a > b) ? a : b)

int main(int argc, const char *argv[]) {
    int num1, num2, num3;

    std::cout << "Input three different integers: ";
    std::cin >> num1 >> num2 >> num3;

    std::cout << "Sum is " << num1 + num2 + num3 << std::endl;
    std::cout << "Average is " << (num1 + num2 + num3) / 3 << std::endl;
    std::cout << "Product is " << num1 * num2 * num3 << std::endl;
    std::cout << "Smallest is " << MIN(num1, MIN(num2, num3)) << std::endl;
    std::cout << "Largest is " << MAX(num1, MAX(num2, num3)) << std::endl;
    return 0;
}

Result


Related Tutorials