prac_011.cpp ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 22 Jun 2026
- License — MIT
Problem Statement ​
Problem Statement
average of elements
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
cpp
#include <iostream>
using namespace std;
class avarage {
int inp[100], sum = 0, n, i;
float avg;
public:
void input();
void calculation();
void output();
};
void avarage::input() {
cout << "\nEnter the number of elements : ";
cin >> n;
i = 0;
while (i < n) {
cout << "\nEnter the element no " << i + 1 << " : ";
cin >> inp[i];
i++;
}
}
void avarage::calculation() {
i = 0;
for (i = 0; i < n; i++) {
sum = sum + inp[i];
}
avg = (float)sum / n;
}
void avarage::output() {
i = 0;
cout << "\nAvarage of the element ";
for (i = 0; i < n; i++) {
cout << " " << inp[i];
}
cout << " is : " << avg;
}
int main() {
avarage z;
z.input();
z.calculation();
z.output();
return 0;
}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
36
37
38
39
40
41
42
43
44
45
46
47
48
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
36
37
38
39
40
41
42
43
44
45
46
47
48