You are viewing a single comment's thread. Return to all comments →
This code seems slow because after having iterated through every integers passed in to get a, you're iterating through a again to find val > 0, cal < 0 val == 0. This is what I did:
cin >> N;
double nP = 0.0, nN = 0.0, nZ = 0.0;
int index = 0, num = 0;
while (index++ < N && cin >> num)
nP += (num > 0);
nN += (num < 0);
nZ += (num == 0);
why you are using .3 in printf
.3f means upto 3 decimal places value will be printed
In fact, you can also get rid of one of the sums in the loop and use just two variables out of the three. You can obtain the other as N - (n1 + n2).
Just replace 1 and 2 with either from P,N or Z as you prefer :).