Answer:
Here is the C++ program to find the largest of three integers.
#include <iostream> //to use input output functions
using namespace std; //to identify objects like cin cout
int main(){ //start of main function
int integer1, integer2, integer3; // declare three integers
cin>>integer1>>integer2>>integer3; //reads values of three integers variables from user
if (integer1 >= integer2 && integer1 >= integer3) //if value of integer1 variable is greater than or equal to both integer2 and integers3 values
cout<<integer1; //then largest number is integer1 and it is displayed
else if (integer2 >= integer1 && integer2 >= integer3) //if value of integer2 variable is greater than or equal to both integer1 and integers3 values
cout<<integer2; //then largest number is integer2 and it is displayed
else //in case value of integer3 variable is greater than or equal to both integer1 and integers2 values
cout<<integer3; } //then largest number is integer3 and it is displayed
Here is the JAVA program to find the largest of three integers.
import java.util.Scanner; //to take input from user
public class Main{
public static void main(String[] args) {//start of main function
Scanner input= new Scanner(System.in); //a standard input stream.
int integer1= input.nextInt();//declare and read value of first integer
int integer2= input.nextInt();//declare and read value of second integer
int integer3= input.nextInt();//declare and read value of third integer
if (integer1 >= integer2 && integer1 >= integer3) //if value of integer1 variable is greater than or equal to both integer2 and integers3 values
System.out.println(integer1); //then largest number is integer1 and it is displayed
else if (integer2 >= integer1 && integer2 >= integer3) //if value of integer2 variable is greater than or equal to both integer1 and integers3 values
System.out.println(integer2); //then largest number is integer2 and it is displayed
else //when value of integer3 variable is greater than or equal to both integer1 and integers2 values
System.out.println(integer3); } } //then largest number is integer3 and it is displayed
Explanation:
The program is well explained in the comments attached with each statement of the program. I will explain the program with the help of an examples. Suppose
integer1 = 7
integer2 = 15
integer3 = 3
first if condition if (integer1 >= integer2 && integer1 >= integer3) checks if value of integer1 variable is greater than or equal to both integer2 and integers3 values. Since integer1 = 7 so it is greater than integer3 = 3 but less than integer2. So this statement evaluates to false because in && ( AND logical operator) both of the conditions i.e integer1 >= integer2 and integer1 >= integer3 should be true. So the program moves to the else if part.
The else if condition else if (integer2 >= integer1 && integer2 >= integer3) checks if value of integer2 variable is greater than or equal to both integer1 and integer3 values. Since integer2 = 15 so it is greater than integer1 = 7 and also greater than integer3 = 3. So this statement evaluates to true as both parts of the else if condition holds true. So the else if part executes which has the statement: cout<<integer2; which prints the value of integer2 i.e. 15 on output screen.
Output:
15