C Program to find maximum and minimum number

Category: C Program

C Program to find the maximum and minimum number

C Program to find maximum and minimum number

#include <stdio.h>

int min(int, int);
int max(int, int);

void main()
{
    int num1, num2;

    printf("Enter first number: ");
    scanf("%d", &num1);
    printf("Enter second number: ");
    scanf("%d", &num2);

    printf("\nMinimum number: %d\n", min(num1, num2));
    printf("Maximum number: %d", max(num1, num2));
}

int min(int num1, int num2)
{
    if (num1 < num2)
        return num1;
    return num2;
}

int max(int num1, int num2)
{
    if (num1 > num2)
        return num1;
    return num2;
}

Output

Enter first number: 5
Enter second number: 4
Minimum number: 4
Maximum number: 5

Recommended Posts