Computer Science, asked by shagufaaa, 4 months ago

write a program to input age of three persons and print the oldest and youngest amongst them​

Answers

Answered by PrimarineRose
13

Answer:

Explanation:

age1 = int(input("Please enter First age: "))

age2 = int(input("Please enter Second age: "))

age3 = int(input("Please enter Third age: "))

list1 = [age1,age2,age3]  #we create a list of the ages

print("The Oldest is: {max(list1)}")  #Largest number in list

print("The Youngest is: {min(list1)}") #Smallest number in list

Answered by anindyaadhikari13
16

Answer:

This is the required program for the question in Java.

import java.util.*;

public class Age  {

   public static void main(String args[])  {

       int age1,age2,age3,max,min;

       Scanner sc=new Scanner(System.in);

       System.out.print("Enter the age of First Person:  ");

       age1=sc.nextInt();

       System.out.print("Enter the age of Second Person:  ");

       age2=sc.nextInt();

       System.out.print("Enter the age of Third Person:   ");

       age3=sc.nextInt();

       if(age1>age2 && age1>age3)

           System.out.println("First Person is the Oldest.");

       else if(age2>age1 && age2>age3)

           System.out.println("Second Person is the Oldest.");

       else if(age3>age1 && age3>age2)

           System.out.println("Third Person is the Oldest.");

       else    {

           System.out.println("All have equal ages.");

           System.exit(0);

       }

       if(age1<age2 && age1<age3)

           System.out.println("First Person is the Youngest.");

       else if(age2<age1 && age2<age3)

           System.out.println("Second Person is the Youngest.");

       else if(age3<age1 && age3<age2)

           System.out.println("Third Person is the Youngest.");

       sc.close();

   }

}

Algorithm:

  1. START.
  2. Accept the ages.
  3. Check if the first age is greater than the second and third age or not. If true, the first person is the eldest. Do the same for other persons.
  4. Similarly, find out the youngest person from the three persons.
  5. STOP.

See the attachment for output.

Attachments:
Similar questions