-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlusMinus
More file actions
42 lines (37 loc) · 775 Bytes
/
PlusMinus
File metadata and controls
42 lines (37 loc) · 775 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
/*
Given an array of integers, calculate the fractions of its elements that are positive, negative, and are zeros.
Print the decimal value of each fraction on a new line.
*/
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n,i;
static int a=0,b=0,c=0;
cin>>n;
int ar[n];
for(i=0;i<n;i++)
{
cin>>ar[i];
}
for(i=0;i<n;i++)
{
if(ar[i]>0)
{
a++;
}
else if(ar[i]==0)
{
b++;
}
else
{
c++;
}
}
cout<<fixed<<setprecision(6)<<(float)a/n<<endl;
cout<<fixed<<setprecision(6)<<(float)c/n<<endl;
cout<<fixed<<setprecision(6)<<(float)b/n<<endl;
return 0;
}