-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRE6.cpp
More file actions
65 lines (60 loc) · 1.06 KB
/
RE6.cpp
File metadata and controls
65 lines (60 loc) · 1.06 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
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
//prototypes here, not needed.
void fillArray(int arr[], int s);
bool findkey(const int arr[], int s, int key);
double getAvg(const int arr[], int s);
int key;
int main()
{
srand(time(0));
const int SIZE = 10;
int array[SIZE];
int key;
fillArray(array, SIZE);
cout << "Enter number you are looking for: " << endl;
cin >> key;
if(findkey(array, SIZE, key))
{
cout << "Found" << endl;
}
else
{
cout << "Not found" << endl;
}
double average = getAvg(array,SIZE);
cout << "The average value of array: " << setprecision(2) << fixed << getAvg(array, SIZE) << endl;
return 0;
}
void fillArray(int arr[], int s)
{
for(int i=0; i < s ; i++)
{
arr[i]= rand() % 100 + 1;
}
}
bool findkey(const int arr[], int s, int key)
{
for(int i = 0; i < s ; i++)
{
if(arr[i]== key)
{
return true;
}
else
{
return false;
}
}
}
double getAvg(const int arr[], int s)
{
int total = 0;
for(int i = 0; i < s; i++)
{
total += arr[i];
}
return (double)total/s;
}