0 votes
125 views
in Programming by (98.9k points)
edited
Write a program in C++ that inputs and stores 10 numbers in an array and prints the sum and average of the array elements?

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
#include <iostream>
using namespace std;

int main() {
 int numArray[10];
 int sum = 0;
 double avg;

 // Input numbers into array
 for (int i = 0; i < 10; i++) {
 cout << "Enter number " << i+1 << ": ";
 cin >> numArray[i];
 sum += numArray[i];
 }

 // Calculate average
 avg = static_cast<double>(sum) / 10;

 // Print sum and average
 cout << "Sum of array elements = " << sum << endl;
 cout << "Average of array elements = " << avg << endl;

 return 0;
}

Related questions

0 votes
1 answer 165 views
0 votes
1 answer 382 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

530 users

...