Amazon Prime




 
Tagged
  • Flow Chart
  •  

    Largest of Two Numbers

    Problem Statement

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

    Algorithm

    1Input : Two numbers a and b
    2Step 1: Start
    3Step 2: Read number a
    4Step 3: Read number b
    5Step 4: if a > b , print a (Compare a and b using greater than operator)
    6Step 5: else print b
    7Step 6: Stop
    8Output : Largest number among a and b
     

     

    Video Explanation

    Flow Chart

    FlowChart LargestOfTwoNumbers

    Code Implementation

    1. Java
    2. C

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

     

  • Flow Chart
  •  
    ...