Given three numbers from user input, decrement the first number by 1 and increment the third number by 2, Then do the magic calculations as follows: get the sum of the first two numbers, deduct the third number from the second and get the product of the first and third number, then sum up the results of the three magic calculations and finally divide you outcome by 3. Sample run 1:
Enter three numbers separated by spaces: 4 2 3
Output: Result of Magic calculations = 5
Sample run 2: Enter three numbers separated by spaces: 2 8 5
Output: Result of Magic calculations = 5
a) Write an Pseudocode to solve the above problem
b) Create a flowchart for the above pseudocode
c) With the help of both your Pseudocode and Flowchart, create a Java program that solves the program as per the given sample out puts and problem description
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
a--;
c += 2;
int sum = a + b;
int sub = b - c;
int mul = a * c;
int result = (sum + sub + mul) / 3;
System.out.println(result);
}
}
Integer a := readInteger()
Integer b := readInteger()
Integer c := readInteger()
a := a - 1
c := c + 2
Integer sum := a + b
Integer sub := b - c
Integer mul := a * c
Integer resul := (sum + sub + mul) / 3
output(result)
Comments
Really helped me with my assignment. Thank you
Leave a comment