You are viewing a single comment's thread. Return to all comments →
In C# i solve simple way with cast
int positiveCount = 0; int negativeCount = 0; int zeroCount = 0;
foreach(int num in arr){ if (num > 0) positiveCount++; else if (num < 0) negativeCount++; else zeroCount++; } double positiveRatio = (double)positiveCount / arr.Count; double negativeRatio = (double)negativeCount / arr.Count; double zeroRatio = (double)zeroCount / arr.Count; Console.WriteLine(positiveRatio.ToString("F6")); Console.WriteLine(negativeRatio.ToString("F6")); Console.WriteLine(zeroRatio.ToString("F6"));
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
In C# i solve simple way with cast