98 875
Assignments Done
98.6%
Successfully Done
In April 2021

# Answer to Question #50597 in C++ for Umer

Question #50597
Write a program that reads a group of numbers from the user and places them in an array of type float. Once the numbers are stored in the array, the program should average them and print the result. Use pointer notation wherever possible.
1
2015-01-30T03:39:56-0500
// main.cpp -- reads group of numbers and finds average of them
#include <iostream>
int main()
{
using namespace std;
// Prompt user to enter number of numbers
int length;
cout << "Enter number of numbers: ";
cin >> length;
// Allocate array for holding numbers
float *arr = new float[length];
for (int i = 0; i < length; ++i)
{
cout << "Enter number #" << (i + 1) << ": ";
cin >> *(arr + i);
}
// Find average value
float average = 0.0F;
for (int i = 0; i < length; ++i)
{
average += *(arr + i);
}
average /= length;
cout << "Average value of entered numbers is " << average << endl;
// Free memory
delete [] arr;
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!