Plus minus
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n; //array size
cin>>n;
int a[n]; //array
double cp=0; //to count number of positive elements
double cn=0; //to count number of negative elements
double cz=0; //to count number of zero elements
for(int i=0;i<n;i++){ //to read and check each array element
cin>>a[i]; //reads array element
if(a[i]>0){ //if positive increment cp
cp++;
}
else if(a[i]<0){ //if negative increment cn
cn++;
}
else{ //else increment cz
cz++;
}
}
cout << fixed << setprecision(6) << cp/n <<endl; //printing the output upto 6 decimal places
cout << fixed << setprecision(6) << cn/n <<endl;
cout << fixed << setprecision(6) << cz/n <<endl;
return 0;
}
0 Comments