Coding Practice
Showing posts with label Find Maximum. Show all posts
Showing posts with label Find Maximum. Show all posts

Write a C program to find maximum between three numbers

Find maximum between three numbers
Sample Output
Enter first number: 56

Enter second number: 98

Enter third number: 37

98 is maximum number.

Process returned 0 (0x0)   execution time : 17.875 s
Press any key to continue.
Source Code
#include<stdio.h>

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

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

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

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

    if(num1 > num2 && num1 > num3)
    {
        printf("\n%d is maximum number.\n", num1);
    }
    else if(num2 > num1 && num2 > num3)
    {
        printf("\n%d is maximum number.\n", num2);
    }
    else
    {
        printf("\n%d is maximum number.\n", num3);
    }
    return 0;
}
Sample Output
Enter first number: 56

Enter second number: 98

Enter third number: 37

98 is maximum number.

Process returned 0 (0x0)   execution time : 17.710 s
Press any key to continue.

Write a C program to find maximum between two numbers

Find maximum between two numbers
Sample Output
Enter first number: 45

Enter second number: 31

45 is maximum number.

Process returned 0 (0x0)   execution time : 6.281 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int num1, num2;

    printf("Enter first number: ");
    scanf("%d", &num1);
    
    printf("\nEnter second number: ");
    scanf("%d", &num2);
 
    if(num1 > num2)
    {
        printf("\n%d is maximum number.\n", num1);
    }
    else
    {
        printf("\n%d is maximum number.\n", num2);
    }
    return 0;
}
Sample Output
Enter first number: -25

Enter second number: 24

24 is maximum number.

Process returned 0 (0x0)   execution time : 8.372 s
Press any key to continue.
Change Theme
X