-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray-analyze-quiz.cpp
More file actions
executable file
·84 lines (55 loc) · 1.78 KB
/
Array-analyze-quiz.cpp
File metadata and controls
executable file
·84 lines (55 loc) · 1.78 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//CSC 160 Quiz #2 Part B
//Purpose: Write exam program
//Author: Larsen J Close Most recent changes: 4/8/16
#include <iostream> // preprocessor directive
#include <iomanip> // needed for most manipulators
using namespace std; // using directive
int main ( void )
{
int k;
int n = 0;
int y = 0;
double average = 0;
int small = 1000;
int array[] = {14, 24, 71, 98, 21, 23, 76, 62, 39};
cout << "(1) Display all array elements: \n";
for(k=0; k<8; k++)
cout << setw(3) << array[k];
cout << "\n\n";
cout << "(2) Search and display smallest integer: ";
while(n<8){
if (array[n] < small)
{
small = array[n];
}
n++;
}
cout << small;
cout << "\n\n";
cout << "(3) Search and display all even integers: \n";
for(k=0; k<8; k++){
if (array[k] % 2 == 0 )
cout << setw(3) << array[k] ;}
cout << " \n\n";
cout << "(4) Calculate and display the average of all elements in array\n";
do{
average = array[y] + average;
y++;
}
while(y<8);
average = average / 9;
cout << fixed << setprecision(2) << average;
cout << "\n\n";
system("pause");
return 0;
} //end main ( )
/* Display of above program
(1) Display all array elements:
14 24 71 98 21 23 76 62
(2) Search and display smallest integer: 14
(3) Search and display all even integers:
14 24 98 76 62
(4) Calculate and display the average of all elements in array
43.22
Press any key to continue . . .
*/