Question

Write a C++ program that has an array of 20 integer numbers. It should call a...

Write a C++ program that has an array of 20 integer numbers. It should call a function to initialize the array. Then it should call a function to find the smallest and average of the array.

1 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ program:-

#include <iostream>

using namespace std;

void arr_init(int* array1, int items){
for (int i = 0; i < items; i++)
{
cout << "Enter a number: " ;
cin >> array1[i];
cout << endl;
}   
}

void arr_min(int arr[],int items){
int min = arr[0];
int i;
for (i = 1; i < items; i++)
{
if (min > arr[i])
min = arr[i];
}

cout << "The smallest number in the list is " << min << endl;
cout << endl;

}

void arr_avg(int arr[],int items){
double sum=0.0;
int i;
for (i = 0; i < items; i++)
{
sum=sum+arr[i];
}
double avg = sum/(double)items;

cout << "The average of elements in the list is " << avg << endl;
cout << endl;

}

int main() {
int arr[20];
arr_init(arr,20);
arr_min(arr,20);
arr_avg(arr,20);
}

Output:-

I performed it for 5 numbers

Stdin Inputs... 20 30 40 50 60 O Execute ave My Projects Recent Collaborate More Options Result... CPU Time: 8.ee sec(s), Mem

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that has an array of 20 integer numbers. It should call a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program - create a 1-d array. Its data type is integer. It has...

    Write a C++ program - create a 1-d array. Its data type is integer. It has 10 elements. - initialize this array by 10 integer numbers. Five elements of the array are positive, and others are negative. - use a while loop to manipulate the array as below. - If the value of an element is positive, the value is doubled. Otherwise, the value is incremented by 3. - print the new value of each element. - use a for...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • C++ C++ Write a program to input eight integer numbers into an array named grade. As...

    C++ C++ Write a program to input eight integer numbers into an array named grade. As each number is input, add the number into a total. After all numbers are input, display the numbers and their average. (You can use cin to take number or use rand() to assign random numbers to the array.)

  • Write a program that dynamically allocates an integer array of size of 20 to hold a...

    Write a program that dynamically allocates an integer array of size of 20 to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to • a function that calculates the average score, the minimal score, and the maximal score in the array, and returns these scores to the main function (hint: use pass by reference, I gave an example in the class) • a function that searches a specific number. The...

  • 2. Write a program that reads N integer numbers of array from the user and then...

    2. Write a program that reads N integer numbers of array from the user and then displays the sum, max number and the numbers of the array use four subroutines ( Read_Array(), Calculate_Sum(), Find_Max() and Display_Array()). Here is sample output Please enter number of elements: 4 Please enter the required numbers: 50 100 150 20 The entered numbers are: 50 100 150 20 Sum is : 320 Max is 150 by Mpsi ,sum and max to call subroutine and retrieve...

  • Write program in C++: Function name: Average1D: The Function takes an integer array of 1 Dimension...

    Write program in C++: Function name: Average1D: The Function takes an integer array of 1 Dimension of any size that is given from the main program. The function returns the average of the numbers that less than or equal to 50.

  • Write a program that first reads an integer for the array size, then reads numbers into...

    Write a program that first reads an integer for the array size, then reads numbers into the array, computes their average, and finds out how many numbers are above the average. Make sure to include pointer syntax. Example output: Enter array size: 10 10 random numbers between 1 and 10 generated are: 2 8 5 1 10 5 9 9 3 5 The average is: 5.7 Number of items above the average = 4 C++ Code only.

  • ***Please complete the code in C*** Write a program testArray.c to initialize an array by getting...

    ***Please complete the code in C*** Write a program testArray.c to initialize an array by getting user's input. Then it prints out the minimum, maximum and average of this array. The framework of testArrav.c has been given like below Sample output: Enter 6 numbers: 11 12 4 90 1-1 Min:-1 Max:90 Average:19.50 #include<stdio.h> // Write the declaration of function processArray int main) I int arrI6]i int min-0,max-0 double avg=0; * Write the statements to get user's input and initialize the...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT