Amazon Prime




 
Tagged
  • Flow Chart
  •  

    Sum of Three Numbers

    Problem Statement

    1Problem Description : Write Algorithm, Flowchart and Program to Add Three Integers
    2
    3Example 1 :
    4 Input : num1 = 3, num2 = 7 and num3 = 5
    5 Output : 15
    6 Explanation : sum of 3, 7 and 5 results to 15
    7
    8Example 2 :
    9 Input : num1 = 12, num2 = 7 and num3 = 1
    10 Output : 20
    11 Explanation : sum of 12, 7 and 1 results to 20

    Algorithm

    1Input : Three numbers num1, num2 and num3
    2
    3Step 1: Start
    4
    5Step 2: Declare sum to 0
    6 (This is optional step, during step5
    7 we can add declaration and assign directly as well)
    8
    9Step 3: Read number num1
    10
    11Step 4: Read number num2
    12
    13Step 5: Read number num3
    14
    15Step 5: Add num1, num2 and num3 and assign result to variable sum
    16
    17Step 6: Print sum
    18
    19Step 7: Stop
    20
    21Output: Sum of num1, num2 and num3

    Flowchart

    Sum of Three Numbers

    Code Implementation

    1. Java
    2. C

    1import java.util.Scanner;
    2
    3public class SumThreeNumbers {
    4
    5 public static void main(String[] args) {
    6 Scanner sc = new Scanner(System.in);
    7
    8 System.out.print("Enter num1: \n");
    9 int num1 = sc.nextInt();
    10
    11 System.out.print("Enter num2: \n");
    12 int num2 = sc.nextInt();
    13
    14 System.out.print("Enter num3: \n");
    15 int num3 = sc.nextInt();
    16
    17 int sum = num1 + num2 + num3 ;
    18 System.out.printf("sum of %d, %d, %d = %d \n", num1, num2, num3, sum);
    19 }
    20}

    Output 1 :

    1Enter num1: 12
    2Enter num2: 7
    3Enter num3: 1
    412 + 7 + 1 = 20
     

    Output 2 :

    1Enter num1: 3
    2Enter num2: 7
    3Enter num3: 5
    43 + 7 + 5 = 15
     

  • Flow Chart
  •  
    ...