-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab 2 Question 2.cpp
More file actions
46 lines (42 loc) · 891 Bytes
/
Lab 2 Question 2.cpp
File metadata and controls
46 lines (42 loc) · 891 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
36
37
38
39
40
41
42
43
44
45
46
//Muhammad Ghazi
//Lab 2, Question 2
#include <iostream>
using namespace std;
int main()
{
int main[5][5];
int sum[5];
int average[5];
int counter = 0;
for (int x = 0; x < 5; x++)
for (int y = 0; y < 5; y++)
{
main[x][y] = 10 + rand() % 91;
}
for (int a = 0; a < 5; a++)
{
int total = 0;
for (int b = 0; b < 5; b++)
{
total += main[b][a];
if (main[b][a] % 2 == 0)
{
counter++;
}
}
sum[a] = total;
average[a] = total/5;
}
cout << "The outputs of the S (sum) array are: " << endl;
for (int i = 0; i < 5; i++)
{
cout << "S[" << i << "] = " << sum[i] << endl;
}
cout << "The outputs of the A (average) array are: " << endl;
for (int j = 0; j < 5; j++)
{
cout << "S[" << j << "] = " << average[j] << endl;
}
cout << "The total number of even numbers are: " << counter << endl;
return 0;
}