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
Expert's answer
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]; // Read numbers 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; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment