Write a C Program to Find maximum of three numbers

Topics

  • The program first declares three variables: num1, num2, and num3.
  • It then prompts the user to enter the three numbers using the printf() and scanf() functions.
  • An if-else statement is used to compare the three numbers. If num1 is greater than or equal to num2 and num3, the program prints the maximum as num1. If num2 is greater than or equal to num1 and num3, the program prints the maximum as num2. Otherwise, the program prints the maximum as num3.
  • Finally, the program returns 0 to indicate successful execution.
  • Note that if two or more numbers are equal and they are the maximum value, the program will consider either number as the maximum.
#include <stdio.h>

int main() {
    int num1, num2, num3;

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

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

    printf("Enter third number: ");
    scanf("%d", &num3);

    if (num1 >= num2 && num1 >= num3) {
        printf("Maximum is %d", num1);
    } else if (num2 >= num1 && num2 >= num3) {
        printf("Maximum is %d", num2);
    } else {
        printf("Maximum is %d", num3);
    }

    return 0;
}

This is a C programming code that finds the maximum value among three input numbers. The code starts by declaring three integer variables num1, num2, and num3 to store the input numbers.

The program then prompts the user to enter the first number, second number, and third number using printf() and reads the input values using scanf() function.

After getting the input values, the program compares them using if-else statements to determine which number is the largest. If num1 is greater than or equal to both num2 and num3, then it is the largest, and the program displays “Maximum is num1”. If num2 is greater than or equal to num1 and num3, then it is the largest, and the program displays “Maximum is num2”. Otherwise, num3 is the largest, and the program displays “Maximum is num3”.

Finally, the program returns 0 to indicate successful execution of the program.

OUTPUT

Enter first number: 56
Enter second number: 23
Enter third number: 78
Maximum is 78

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *