-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18.cpp
More file actions
35 lines (27 loc) · 810 Bytes
/
18.cpp
File metadata and controls
35 lines (27 loc) · 810 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
31
32
33
34
35
// C++ program to find the sum and average of 'n' numbers.
#include <iostream>
#define SIZE 100
using std::cin, std::cout;
int main()
{
// declaring the required variables.
int a[SIZE], i, number, sum = 0;
float average;
// entering the values for the variables from the console.
cout << "Enter the number of elements: ";
cin >> number;
cout << "Enter the elemets: ";
for(i = 0; i < number; ++i)
{
cin >> a[i];
}
// calculating the sum and avarage of 'n' numbers.
for(i = 0; i < number; ++i)
{
sum += a[i];
}
average = (float)sum / number;
// printing the calculated sum and average of 'n' numbers to the console.
cout << "Sum: " << sum << "\n";
cout << "Average: " << average;
}