Amazon Prime




 
Tagged
  • Flow Chart
  •  

    Largest of Three Numbers

    Problem Statement

    1Problem Description : Find the largest of three numbers.
    2
    3Example 1 :
    4Input : a = 3, b = 7 and c = 4
    5Output : 7
    6Explanation : 7 is the largest number.
    7
    8Example 2 :
    9Input : a = 12, b = 1 and c = 7
    10Output : 12
    11Explanation : 12 is the largest number.

    Algorithm

    1Input : Three numbers a, b and c
    2Step 1: Start
    3Step 2: Read number a
    4Step 3: Read number b
    5Step 4: Read number c
    6Step 5: if a > b Goto Step 6, else Goto Step 7
    7Step 6: if a > c Print a, else Print c
    8Step 7: if b > c Print b, else Print c
    9Step 8: Stop
    10Output : Largest number among a, b and c
     

     

    Flow Chart

    Flowchart - Largest of Three Numbers

    Code Implementation

    1. Java
    2. C

    1import java.util.Scanner;
    2
    3public class LargestOfThreeNumbers {
    4
    5 public static void main(String[] args) {
    6 int a, b, c;
    7 Scanner sc = new Scanner(System.in);
    8
    9 System.out.print("Enter a: ");
    10 a = sc.nextInt();
    11 System.out.print("Enter b: ");
    12 b = sc.nextInt();
    13 System.out.print("Enter c: ");
    14 c = sc.nextInt();
    15
    16 if (a > b) {
    17 if (a > c) {
    18 System.out.printf("Largest Number is : %d \n", a);
    19 } else {
    20 System.out.printf("Largest Number is : %d \n", c);
    21 }
    22 } else {
    23 if (b > c) {
    24 System.out.printf("Largest Number is : %d \n", b);
    25 } else {
    26 System.out.printf("Largest Number is : %d \n", c);
    27 }
    28 }
    29 }
    30}

    Output 1:

    1Enter a : 27
    2Enter b : 3
    3Enter c : 7
    4Largest Number is : 27
     

    Output 2:

    1Enter a: 5
    2Enter b: 17
    3Enter c: 8
    4Largest Number is : 17
     

  • Flow Chart
  •  
    ...