Write a C program ( not c++) that prints user entered integers on a single line.
ID: 3776446 • Letter: W
Question
Write a C program ( not c++) that prints user entered integers on a single line. They choose the size of the array. The program must also print the second half of the array in reverse AND find the average of the second half of integersIn main you must prompt the user to enter length of array. And call both functions
Must use two functions: 1. Void inputvalues( Int arrayLen, int arrayToFill[]);
2. Void printArray( int length, int toPrint[]); use loops in this function
Write a C program ( not c++) that prints user entered integers on a single line. They choose the size of the array. The program must also print the second half of the array in reverse AND find the average of the second half of integers
In main you must prompt the user to enter length of array. And call both functions
Must use two functions: 1. Void inputvalues( Int arrayLen, int arrayToFill[]);
2. Void printArray( int length, int toPrint[]); use loops in this function
In main you must prompt the user to enter length of array. And call both functions
Must use two functions: 1. Void inputvalues( Int arrayLen, int arrayToFill[]);
2. Void printArray( int length, int toPrint[]); use loops in this function
Must use two functions: 1. Void inputvalues( Int arrayLen, int arrayToFill[]);
2. Void printArray( int length, int toPrint[]); use loops in this function
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int size;
double sum = 0;
double avg;
cout << "How many numbers? ";
cin >> size;
// dynamically allocate array
int * array = new int[size];
// first loop - get the data
for (int count=0; count<size; count++)
{
cout << "Enter Number: ";
cin >> array[count];
}
// second loop - accumulate the total
for (int count=0; count<size; count++)
sum += array[count];
cout << "The sum is " << sum << endl;
avg = sum / size;
cout << "The average is " << avg << endl;
// de-allocate the array
delete [] array;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.