Amazon Prime




 
Tagged
  • Flow Chart
  •  

    Sum of Two Numbers

    Problem Statement

    1Problem Description :
    2Write Algorithm, Flowchart and Program to Add Two Integers
    3
    4Example 1 :
    5 Input : a = 3 and b = 7
    6 Output : 10
    7 Explanation : sum of 3 and 7 results to 10
    8
    9Example 2 :
    10 Input : a = 12 and b = 7
    11 Output : 19
    12 Explanation : sum of 12 and 7 results to 19

    Algorithm

    1Input : Two numbers num1 and num2
    2Step 1: Start
    3Step 2: Declare sum to 0 (This is optional step, during step5 we can add declaration and assign directly as well)
    4Step 3: Read number num1
    5Step 4: Read number num2
    6Step 5: Add num1 and num2 and assign result to variable sum
    7Step 6: Print sum
    8Step 7: Stop
    9Output: Sum of num1 and num2

    Video Explanation

    Flowchart

    Sum of Two Numbers - Flowchart

    Code Implementation

    1. Java
    2. C

    1import java.util.Scanner;
    2
    3public class SumOfTwoNumbers {
    4
    5 public static void main(String[] args) {
    6
    7 // Initialize scanner to which is used to read inputs
    8 Scanner sc = new Scanner(System.in);
    9
    10 // Read number1 and number 2
    11 System.out.print("Enter num1: ");
    12 int num1 = sc.nextInt();
    13 System.out.print("Enter num2: ");
    14 int num2 = sc.nextInt();
    15
    16 // calculate sum
    17 int sum = num1 + num2;
    18
    19 //print sum
    20 System.out.printf("%d + %d = %d \n", num1, num2,sum);
    21 }
    22}

    1Output 1 :
    2Enter number1: 10
    3Enter number2: 23
    410 + 23 = 33
     
    1Output 2 :
    2Enter number1: 2
    3Enter number2: 12
    42 + 12 = 14
     

  • Flow Chart
  •  
    ...