-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplus_minus.cpp
More file actions
44 lines (34 loc) · 985 Bytes
/
plus_minus.cpp
File metadata and controls
44 lines (34 loc) · 985 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
/*
arr = [1, 1, 0, -1, -1]
1. find positives
2. find negatives
3. find zeros
4. get/ print ratios of each
float positive{ 0.0 }, negative{ 0.0 }, zero{ 0.0 };
for (int i = 0; i < arr.size(); i++)
{
if (arr.at(i) > 0) zero++;
else if (arr.at(i) < 0) negative++;
else zero++;
printf("%f %f %f\n",(float(arr.size()) / positive), (float(arr.size()) / negative... etc))
}
*/
#include <bits/stdc++.h>
void plus_minus(std::vector<int> arr)
{
float positive{ 0.0 }, negative{ 0.0 }, zero{ 0.0 };
int i;
for (i = 0; i < arr.size(); i++)
{
if (arr.at(i) > 0) positive++;
else if (arr.at(i) < 0) negative++;
else zero++;
}
printf("%f\n%f\n%f\n",(positive / float(arr.size())), (negative / float(arr.size())), (zero / float(arr.size())));
}
int main(int argc, char const *argv[])
{
std::vector<int> arr{ -4, 3, -9, 0, 4, 1 };
plus_minus(arr);
return 0;
}