Question

In: Computer Science

Design the logic for a program that allows a user to enter 20 numbers, then displays...

Design the logic for a program that allows a user to enter 20 numbers, then displays them in the reverse order of entry.

Design the logic for a program that allows a user to enter 20 numbers, then displays each number and its difference from the numeric average of the numbers entered.

The program is C++. I need a Pseudocode

Solutions

Expert Solution

Code (first one)

#include<iostream>
using namespace std;

int main()
{
    int a[20]; // create array of 20 elements
    for(int i=0;i<20;i++)
    {
        cin>>a[i];
    }
    cout<<"values in reversed order\n";
    for(int i=19;i>=0;i--)
    {
        cout<<a[i]<<" ";
    }
    return 0;
}

Pseudocode (first one)

  • create array a with 20 elements.
  • for i 0 to 20(20 exclusive) ,get user input and store input as a[i]
  • for i 19 to 0(0 inclusive) print a[i]

Code(second one)

#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
    int a[20]; // create array of 20 elements
    for(int i=0;i<20;i++)
    {
        cin>>a[i];
    }
    int sum=0;
    for(int i=0;i<20;i++)
    {
        sum=sum+a[i];
    }
    cout<<"number and thier difference with avg\n";
    int avg=sum/20;
    for(int i=0;i<20;i++)
    {
        cout<<a[i]<<" "<<abs(a[i]-avg)<<"\n";
    }
    return 0;
}

Pseudocode

  • create array a with 20 elements
  • for i to 20 get user input and store it as a[i]
  • sum=0
  • for i to 20(20 exclusive), sum =sum+a[i]
  • avg=sum/20
  • for i to 20(20 exclusive), print a[i] abs(a[i]-avg)

Terminal Work(first one)

Terminal Work(second one)

.


Related Solutions

Design a modular program which asks the user to enter a list of numbers. The numbers...
Design a modular program which asks the user to enter a list of numbers. The numbers must be stored in an array. The program then finds the index of the first occurrence of the smallest element in the array and the last occurrence of the largest element in the array. The program displays the position and value of each of these items.
can someone please check this code? – Enter Quantity of Numbers Design a program that allows...
can someone please check this code? – Enter Quantity of Numbers Design a program that allows a user to enter any quantity of numbers until a negative number is entered. Then display the highest number and the lowest number. For the programming problem, create the pseudocode and enter it below. Enter pseudocode here start     Declarations           num number           num high             num low              housekeeping()     while number >=0 detailLoop()      endwhile      finish() stop housekeeping( )           output...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Using Java, design a program to let user enter two lists of numbers within the range...
Using Java, design a program to let user enter two lists of numbers within the range [0, 9] from keyboard, you could either use flag to denote end of the list or ask user to enter the list size first and then enter the list numbers. Each of these two lists represents a set (keep in mind that duplicate elements are not allowed in the same set but are allowed between sets), so we have two sets A and B....
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters...
Write Java code that allows a user to repeatedly enter numbers. Each time the user enters a number, the program should print out the average of the last 3 numbers (or all numbers if 3 or less have been entered). I would like a detailed explanation so that a beginner level Java programmer could understand.
The program asks user to enter three integers, and the displays a message indicating whether the...
The program asks user to enter three integers, and the displays a message indicating whether the numbers are in sequential order, in reverse order or in neither order. Find the errors and correct the program codes in the if comparison expressions. (10 points) 1.     using System; 2.     using static System.Console; 3. 4.     class Sorting 5.     { 6.              static void Main() 7.              { 8.                       int num1, num2, num3; 9.                       string snum1, snum2, snum3; 10.                    Write ("Enter first number "); 11.                    snum1...
Design a program that displays the following in Java: Enter the grades for an Essay: Grammer...
Design a program that displays the following in Java: Enter the grades for an Essay: Grammer (must be 30 or less): 40 Grammer (must be 30 or less): 26.3 Spelling (must be 20 or less): 17.4 Correct Length (must be 20 or less): 19 Content (must be 30 or less): 23.5 The recorded scores are: Grammer: 26.3 Spelling: 17.4 Correct Length: 19.0 Content: 23.5 Total score: 86.2 The grade for this essay is B
C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT