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

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...
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...
In C code format please! 4.16 LAB: Checker for integer string Forms often allow a user...
In C code format please! 4.16 LAB: Checker for integer string Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. You may assume that the string does not contain spaces and will always contain less than 50 characters. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or 1995! the...
Write a java code that gets student test scores from the user. Each test score will...
Write a java code that gets student test scores from the user. Each test score will be an integer in the range 0 to 100. Input will end when the user enters -1 as the input value. After all score have been read, display the number of students who took the test, the minimum score, the maximum score, the average score (with decimal point, and the number of A where an A is a score in the range 90-100.
Translate the following Code into MIPS (.asm) Arrays and Reentrant Subprograms CallingSubroutinesDemo.asm Implement the following pseudo...
Translate the following Code into MIPS (.asm) Arrays and Reentrant Subprograms CallingSubroutinesDemo.asm Implement the following pseudo code in a program called SubRoutinePractice.asm. Be sure to follow proper protocol for calling subroutines. Implement a prolog and epilog. // Main routine asks for three numbers from the user. Stores them in $s0, $s1 and $s2 // It then calls a subroutine that determines the largest and sum. // Program then prints the results main() { // $s0, $s1 and $s2 hold input...
What will be the expected output of the following pseudo code? Write exactly what would display...
What will be the expected output of the following pseudo code? Write exactly what would display when you execute the statements. Module main() Declare Integer a = 5 Declare Integer b = 2 Declare Integer c = 3 Declare Integer result = 0 Display "The value of result is" Display result Set result = a + b * c - a Display "Changed value is: ", result End Module
(Artificial Intelligence) Write a pseudo code for the following: Regular Hill Climbing with steepest ascent
(Artificial Intelligence) Write a pseudo code for the following: Regular Hill Climbing with steepest ascent
For the following program descriptions, write step by step pseudo code that shows you understand the...
For the following program descriptions, write step by step pseudo code that shows you understand the problem and what it takes to solve it. The first one is done for you as an example. Please answer the questions in the same format as the example problem below so it is the same. Example #1 Problem A customer is purchasing five items. Design a program where you collect the amount of each item, calculate the subTotal of the items, the tax...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT