Computer Science, asked by angelmukhia6, 7 months ago

1. Write a program to find out the greatest of any three number​

Answers

Answered by Anonymous
1

C++

#include <iostream>

long Get_Greater_Number(long number1, long number2)

{

   if (number1 > number2)

       return number1;

   else

       return number2;

}

int main()

{

   long num1, num2, num3;

   std::cout << "Enter first number: ";

   std::cin >> num1;

   std::cout << "\nEnter second number: ";

   std::cin >> num2;

   std::cout << "\nEnter third number: ";

   std::cin >> num3;

   long g1 = Get_Greater_Number(num1, num2);

   long g2 = Get_Greater_Number(g1, num3);

   std::cout << "\nGreater number is: " << g2 << "\r\n";

   std::system("pause");

   return 0;

}

Java

import java.util.Scanner;

class greater {

   public static void main(String[] args) {

       Print("Enter first number: ");

       Scanner getInput1 = new Scanner(System.in);

       long i = getInput1.nextLong();

       Print("\nEnter second number: ");

       Scanner getInput2 = new Scanner(System.in);

       long j = getInput2.nextLong();

       Print("\nEnter third number: ");

       Scanner getInput3 = new Scanner(System.in);

       long k = getInput3.nextLong();

       long greater = Greater_Number(i, j);

       Print("Greater number is: " + Greater_Number(k, greater));

       getInput1.close();

       getInput2.close();

       getInput3.close();

   }

   public static void Print(Object _object_) {

       System.out.print(_object_);

   }

   public static long Greater_Number(long Number1, long Number2) {

       if (Number1 > Number2) {

           return Number1;

       } else {

           return Number2;

       }

   }

}

Python

def _greater_number_(number1, number2):

   if(int(number1) > int(number2)):

       return int(number1)

   else:

       return int(number2)

i = eval(input("Enter first number: "))

j = eval(input("Enter second number: "))

k = eval(input("Enter third number: "))

g1 = _greater_number_(i, j)

g2 = _greater_number_(g1, k)

print("Greater number =" , g2)

Answered by anindyaadhikari13
2

Question:-

Write a program to find out the greatest among 3 numbers.

Program:-

Here is the code, written in Java.

import java.util.*;

class Max

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the first number: ");

int a=sc.nextInt();

System.out.print("Enter the second number: ");

int b=sc.nextInt();

System.out.print("Enter the third number: ");

int c=sc.nextInt();

System.out.println("Largest Number is: "+Math.max(a, Math.max(b, c)));

}

}

Similar questions