Question

In: Computer Science

Develop the pseudo code for, desk check and test the following programs. Allow the user to...

Develop the pseudo code for, desk check and test the following programs. Allow the user to provide the number of elements, and initialise the array according to their input. Use functions where appropriate to ensure modularity. 1. Find the average of a list of numbers 2. Find the smallest element in a list of numbers

Solutions

Expert Solution

Solution:

I am writing the program in java language. Please comment in case of any doubt.

//Code is as follows

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

//provide the number of elements        

System.out.print("Enter number of elments: ");

int n = sc.nextInt();

//initialise the array according to their input

int nums[] = new int[n];

System.out.println("Enter "+n+" numbers: ");

for(int i=0; i<n; i++)

{

nums[i] = sc.nextInt();

}

//Find the average of a list of numbers

double avg = 0.0;

for(int i=0; i<n; i++)

{

avg += nums[i];

}

avg /= n;

//Find the smallest element in a list of numbers

int smallest = nums[0];

for(int i=1; i<n; i++)

{

if(smallest>nums[i])

smallest = nums[i];

}

//print entered elements

System.out.println("Entered numbers are: ");

for(int i=0; i<n; i++)

{

System.out.print(nums[i]);

if(i!=n-1)

System.out.print(", ");

}

//print average and smallest element

System.out.printf("\nAverage is: %.2f\n", avg);

System.out.printf("Smallest Element is: %d\n",smallest);

}

}

Output:

Please give thumbsup, if you like it. Thanks.


Related Solutions

Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
Question 1. The following code asks the user to enter the password and check it with...
Question 1. The following code asks the user to enter the password and check it with the pre-defined password that stored in the system. If the entered password is correct, it will authenticate the user to log-in into the account, otherwise reject! Analyze the following code, how it works? Do you think this code is safe? Justify? Try to overwrite this code and report the outputs? Define any vulnerabilities in this code if exist? What we can do to make...
For this exercise, you will implement two programs that allow the user to enter grades in...
For this exercise, you will implement two programs that allow the user to enter grades in a gradebook. The first program will use one‐dimensional arrays, and the second program will use two‐dimensional arrays. The two programs function the same Write an application that prints out the final grade of the students in a class and the average for the whole class. There are a total of 3 quizzes. You will need 4 arrays: 1. An array of type int to...
n this assignment, you will need to code a Web page that will allow a user...
n this assignment, you will need to code a Web page that will allow a user to enter their first and last names and indicate how many pets they have, if any. If they have pets, the user will be able to list up to three of their names. You will code validations on some of the fields and display error messages on the page when a field does not pass the validation test. If all the data entered is...
CODE IN PYTHON: Your task is to write a simple program that would allow a user...
CODE IN PYTHON: Your task is to write a simple program that would allow a user to compute the cost of a road trip with a car. User will enter the total distance to be traveled in miles along with the miles per gallon (MPG) information of the car he drives and the per gallon cost of gas. Using these 3 pieces of information you can compute the gas cost of the trip. User will also enter the number of...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user to enter a part into the inventory, take a part from the inventory, or quit. You are provided with the InvItem class (InvItem.h) and a partial Driver.cpp. You will be creating a DynamicStack class that should implement a Stack data structure. The DynamicClass should be implemented as a template class to allow any data type be added/removed from the stack. You will submit three...
In C++ 2. Test Scores #2 Modify the program #1 to allow the user to enter...
In C++ 2. Test Scores #2 Modify the program #1 to allow the user to enter name-score pairs. For each student taking a test, the user types a string representing the name of the student, followed by an integer representing the student's score. (use a structure) Modify the average-calculating function so they take arrays of structures, with each structure containing the name and score of a single student. In traversing the arrays, use pointers notation rather than array indices. (myArray->name...
Write a code in Python jupytoer note book: Ask the user to input a year. Check...
Write a code in Python jupytoer note book: Ask the user to input a year. Check if this is a leap year or not. Ask the user to input a number. Check if this number is even or odd. HbA1c of 6.5% or higher indicates diabetes. 5.7 to 6.4 indicates pre-diabetes. HbA1c less than 5.7 is considered normal. Ask the user for their HbA1c level and display if their they are in the normal range, pre-diabetic, or diabetic. Ask the...
Use pseudo code to plan a programming solution for the following: A GUI interface to ensure...
Use pseudo code to plan a programming solution for the following: A GUI interface to ensure a user is old enough to play a game. See additional resources above for additional resources. Properly formatted prompts to input name, address, phone number, and age. Instructions to ensure that the information is displayed back to the user. Also, the user must be 21. So, include instructions to display an appropriate message about whether or not the user can continue. Instructions that will...
Reuse the code to prompt the user for a specific day, test whether it is within...
Reuse the code to prompt the user for a specific day, test whether it is within range, and then output the estimated concrete strength from the fitted curve using polyval. Run your function from the command window for 2 different days to test the functioning of your code. The program should preferably loop until the user asks to exit. where x = days y = rain (mm) x = [0 1 2 3 7 14 28]; y = [0 4...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT