Program to find greatest of 3 numbers

Description

Greatest of 3 number will the number greater than other 2 number.

C/C++

/* C Program to find greatest of 3 numbers */
//Save it as Greatest3Numbers.c

#include<stdio.h>
int main(){

    int number1, number2, number3;

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

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

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

    if(number1>number2 && number1>number3){
        printf("%d is greater than %d and %d",number1,number2,number3);
    }else if(number2>number1 && number2>number3){
        printf("%d is greater than %d and %d",number2,number1,number3);
    }else{
        printf("%d is greater than %d and %d",number3,number1,number2);
    }
    return 0;
Input:
Enter first number : 9
Enter second number : 8
Enter third number : 5

Output:
9 is greater than 8 and 5

Java

/* Java Program to find greatest of 3 numbers */
//Save it as Greatest3Numbers.java

import java.io.*;
import java.util.Scanner;
public class Greatest3Numbers {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        
        int number1, number2, number3;

        System.out.println("Enter first number : ");
        number1 = scanner.nextInt();

        System.out.println("Enter second number : ");
        number2 = scanner.nextInt();

        System.out.println("Enter third number : ");
        number3 = scanner.nextInt();

        if(number1>number2 && number1>number3){
            System.out.println(number1+" is greater than "+number2+" and "+number3);
        }else if(number2>number1 && number2>number3){
        	System.out.println(number2+" is greater than "+number1+" and "+number3);
        }else{
        	System.out.println(number3+" is greater than "+number1+" and "+number2);
        }
    }
}
Input:
Enter first number : 
9
Enter second number : 
8
Enter third number : 
5

Output:
9 is greater than 8 and 5

Related Programs

1) Program to calculate Grade of Student
2) Program to find sum of digits of a number
3) Program to reverse a number
4) Program to display multiplication table of a number
5) Program to find sum of first and last digit of a number
6) Program to find factors of a Number
7) Program to find largest and smallest digit in a Number
8) Program to add two complex numbers
9) Program to calculate Volume and Surface Area of Sphere
10) Program to Check Leap Year
Share Me

Leave a Reply