C++ program to find maximum and minimum of n numbers || C++
In this, we are going see a program on maximum and minimum of n numbers in C++ Programming Language.


The Code given below can be used in TURBO C++ Compilers: -

#include <iostream.h>
#include<conio.h>
#include <stdio.h>
#include <string.h>

#define max(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define min(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))

int main()
{
    clrscr();
    int n1, n2, n3;
    cout << "Enter n1,n2,n3: ";
    cin >> n1 >> n2 >> n3;
    cout << "Maximum of the 3 numbers: " << max(n1, n2, n3) << "\n";
    cout << "Minimum of the 3 numbers: " << min(n1, n2, n3);
    getch();
    return 0;
}


The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;

#define max(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define min(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))

int main()
{
    int n1, n2, n3;
    cout << "Enter n1,n2,n3: ";
    cin >> n1 >> n2 >> n3;
    cout << "Maximum of the 3 numbers: " << max(n1, n2, n3) << "\n";
    cout << "Minimum of the 3 numbers: " << min(n1, n2, n3);
    return 0;
}

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post