Write a C program to find the max and min of four numbers using if-else.

 Write a C program to find the max and min of four numbers using if-else.

Program:

#include <stdio.h>


int main() {

    int a, b, c, d;

    int max, min;


    // Input four numbers

    printf("Enter four numbers: ");

    scanf("%d %d %d %d", &a, &b, &c, &d);


    // Finding maximum

    if (a > b && a > c && a > d)

        max = a;

    else if (b > c && b > d)

        max = b;

    else if (c > d)

        max = c;

    else

        max = d;


    // Finding minimum

    if (a < b && a < c && a < d)

        min = a;

    else if (b < c && b < d)

        min = b;

    else if (c < d)

        min = c;

    else

        min = d;


    // Output results

    printf("Maximum = %d\n", max);

    printf("Minimum = %d\n", min);


    return 0;

}

Output:


Comments