forked from waboke/solutions_to_pastquestions_2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsumofnum.cpp
More file actions
30 lines (24 loc) · 768 Bytes
/
sumofnum.cpp
File metadata and controls
30 lines (24 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
// Function to compute sum and average
void computeSumAndAverage(int* arr, int size, int* sum, float* average) {
*sum = 0;
for (int i = 0; i < size; ++i) {
*sum += *(arr + i); // Add elements to sum
}
*average = static_cast<float>(*sum) / size; // Calculate average
}
int main() {
const int size = 10;
int numbers[size];
int sum;
float average;
cout << "Enter 10 numbers:" << endl;
for (int i = 0; i < size; ++i) {
cin >> *(numbers + i); // Store input using pointer notation
}
computeSumAndAverage(numbers, size, &sum, &average);
cout << "Sum of the numbers: " << sum << endl;
cout << "Average of the numbers: " << average << endl;
return 0;
}