1#include <iostream>
2using namespace std;
3
4int main() {
5 int numbers[5] = {7, 5, 6, 12, 35};
6
7 cout << "The numbers are: ";
8
9 // Printing array elements
10 // using range based for loop
11 for (const int &n : numbers) {
12 cout << n << " ";
13 }
14
15
16 cout << "\nThe numbers are: ";
17
18 // Printing array elements
19 // using traditional for loop
20 for (int i = 0; i < 5; ++i) {
21 cout << numbers[i] << " ";
22 }
23
24 return 0;
25}
1#include <iostream>
2using namespace std;
3
4int main() {
5
6 // initialize an array without specifying size
7 double numbers[] = {7, 5, 6, 12, 35, 27};
8
9 double sum = 0;
10 double count = 0;
11 double average;
12
13 cout << "The numbers are: ";
14
15 // print array elements
16 // use of range-based for loop
17 for (const double &n : numbers) {
18 cout << n << " ";
19
20 // calculate the sum
21 sum += n;
22
23 // count the no. of array elements
24 ++count;
25 }
26
27 // print the sum
28 cout << "\nTheir Sum = " << sum << endl;
29
30 // find the average
31 average = sum / count;
32 cout << "Their Average = " << average << endl;
33
34 return 0;
35}