Program to find the greatest of two numbers and greatest of three numbers

Program to find the greatest of two numbers and greatest of three numbers is discussed here. Input two or integers from the user and find the greatest number among them.

Input & Output format:

      Input consists of 2 integers.

Sample Input and Output :

7
9
5

9 is greater.

Algorithm to find the greatest of two numbers and greatest of three numbers

Greatest_of_two_numbers(num1, num2):

  • If (num1 > num2)
  • Print num1
  • Else, print num2

Greatest_of_three_numbers(num1,num2):

  • If (num1 > num2) and (num1 > num3)
  • Print num1
  • Else if (num2 > num1) and (num 2 > num3)
  • Print num2.
  • Else, print num3

Program to find the greatest of two numbers and greatest of three numbers are given below

  • Edit

Program to find the greatest of two numbers

// C program to find the greatest of two numbers

#include<stdio.h>
int main()
{
//Fill the code
int num1, num2;
scanf(“%d %d”,&num1,&num2);
if(num1 > num2)

printf(“%d is greater”,num1);
}
else
{
printf(“%d is greater”,num2);
}
return 0;
}

// C++ program to find the greatest of two numbers

#include<iostream>
using namespace std;

int main()
{
//Fill the code
int num1, num2;
cin >> num1 >> num2;
if(num1 > num2)
{
cout << num1 << ” is greater” << endl;
}
else
{
cout << num2 << ” is greater” << endl;
}
return 0;
}

// Java program to find the greatest of two numbers

import java.util.*;
public class Main
{
public static void main(String[] args) 
{
Scanner sc = new Scanner(System.in);
int num1,num2;
num1 = sc.nextInt();
num2 = sc.nextInt();
if(num1 > num2)
System.out.print(num1 + ” is greater”);
else
System.out.print(num2 + ” is greater”);
}
}

# Python program to find the greatest of tw numbers

num1 = int(input())
num2 = int(input())
print(max(num1,num2),”is greater”)

Program to find the greatest of three numbers

// C program to find the greatest of three numbers

#include<stdio.h>
int main()
{
//Fill the code
int num1, num2, num3;
scanf(“%d %d %d”,&num1,&num2,&num3);
if(num1 > num2 && num1 > num3)

printf(“%d is greater”,num1);
}
else if(num2 > num1 && num2 > num3)
{
printf(“%d is greater”,num2);
}
else
{
printf(“%d is greater”,num3);
}
return 0;
}

// C++ program to find the greatest of three numbers

#include<iostream>
using namespace std;

int main()
{
//Fill the code
int num1, num2, num3;
cin >> num1 >> num2 >> num3;
if(num1 > num2 && num1 > num3)
{
cout << num1 << ” is greater” << endl;
}
else if(num2 > num1 && num2 > num3)
{
cout << num2 << ” is greater” << endl;
}
else
{
cout << num3 << ” is greater” << endl;
}
return 0;
}

// Java program to find the greatest of three numbers

import java.util.*;
public class Main
{
public static void main(String[] args) 
{
Scanner sc = new Scanner(System.in);
int num1,num2,num3;
num1 = sc.nextInt();
num2 = sc.nextInt();
num3 = sc.nextInt();
if(num1 > num2 && num1 > num3)
System.out.print(num1 + ” is greater”);
else if(num2 > num1 && num2 > num3)
System.out.print(num2 + ” is greater”);
else
System.out.print(num3 + ” is greater”);

}
}

# Python program to find the greatest of three numbers

num1 = int(input())
num2 = int(input())
num3 = int(input())
print(max(num1,num2,num3),”is greater”)

Output:

greatest of two numbers and greatest of three numbers