[Solved] Maximum of 3 Numbers with Java, C++, Python

Write a program to find the maximum of 3 numbers using functions.

Input Format:

Input consists of 3 integers.

Output Format:

Refer sample output for formatting details.

Sample Input:

13

45

23

Sample Output:

45 is the maximum number

Solution

import java.util.Scanner;

class Main
{
public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        int a, b, c;
        a = s.nextInt();
        b = s.nextInt();
        c = s.nextInt();
        int max = findmaximum(a, b, c);
        //sauravhathi
        System.out.println(max + " is the maximum number");
    }
    
public static int findmaximum(int x, int y, int z)
    {
        int r;
        if (x > y && x > z)
        {
            r = x;
        }
        else if (y > z)
        {
            r = y;
        }
        else
        {
            r = z;
        }
        return r;
    }
}
#include <iostream>
using namespace std;

int findmaximum(int a, int b, int c)
{
    int max = a;
    if (b > max)
    {
        max = b;
    }
    if (c > max)
    {
        max = c;
    }
    return max;
}

int main()
{
    int a, b, c;
    cout << "Enter the value of a" << endl;
    cin >> a;
    cout << "Enter the value of b" << endl;
    cin >> b;
    cout << "Enter the value of c" << endl;
    cin >> c;

    cout << "Maximum element is " << findmaximum(a, b, c) << endl;
    return 0;
}
def findmaximum(x, y, z):
    if x > y and x > z:
        return x
    elif y > z:
        return y
    else:
        return z
        #sauravhathi

a = int(input("Enter the value of a"))
b = int(input("Enter the value of b"))
c = int(input("Enter the value of c"))
max = findmaximum(a, b, c)
print("Maximum element is", max)

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

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