In: Computer Science
DESIGN A FLOWCHART IN THE APPLICATION FLOWGORITHM
Exercise called: Number Analysis Program
Design a program that asks the user to enter a maximum of 20 numbers. The program should store the numbers in an array and then display the following data:
1-The lowest number in the array.
2-The highest number in the array.
3-The total of the numbers in the array.
4-The average of the numbers in the array.
PLEASE AND THANK YOU
The Flowchart for the above Program in Flowgorithm is :-
Example Output :-
Enter the amount of numbers you want to add in array
,Maximum-20
10
Enter the numbers to assign in Array
1
2
3
4
5
6
7
8
9
10
Largest element is 10
Smallest element is1
Sum is55
Average is5.5
Code in Java for above program :-
import java.util.*;
import java.lang.Math;
public class JavaApplication {
private static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int[] numbers = new int[20];
int nums;
System.out.println("Enter the amount of numbers you want to add in array ,Maximum-20");
nums = input.nextInt();
System.out.println("Enter the numbers to assign in Array");
int count;
count = 0;
int smallest;
int largest;
int sum;
sum = 0;
double average;
average = 0;
while (count < nums) {
numbers[count] = input.nextInt();
if (count == 0) {
largest = numbers[count];
smallest = numbers[count];
} else {
if (count > 0 && numbers[count] > numbers[count - 1]) {
largest = numbers[count];
}
if (count > 0 && numbers[count] < numbers[count - 1]) {
smallest = numbers[count];
}
}
sum = sum + numbers[count];
count = count + 1;
}
average = (double) sum / nums;
System.out.print("Largest element is ");
System.out.println(largest);
System.out.print("Smallest element is");
System.out.println(smallest);
System.out.print("Sum is");
System.out.println(sum);
System.out.print("Average is");
System.out.println(average);
}
}
The pseudocode for above flowchart is :-
Function Main
Declare Integer Array Numbers[20]
Declare Integer nums
Output "Enter the amount of numbers you want to add in array
,Maximum-20"
Input nums
Output "Enter the numbers to assign in Array"
Declare Integer count
Assign count = 0
Declare Integer smallest
Declare Integer largest
Declare Integer sum
Assign sum = 0
Declare Real average
Assign average = 0
While count<nums
Input Numbers[count]
If count==0
Assign largest = Numbers[count]
Assign smallest = Numbers[count]
False:
If count>0 && Numbers[count]>Numbers[count-1]
Assign largest = Numbers[count]
End
If count>0 && Numbers[count]< Numbers[count-1]
Assign smallest = Numbers[count]
End
End
Assign sum = sum+ Numbers[count]
Assign count = count+1
End
Assign average = sum/nums
Output "Largest element is "
Output largest
Output "Smallest element is"
Output smallest
Output "Sum is"
Output sum
Output "Average is"
Output average
End