+ 2

# PlusMinusZero Ratio Values in Array with 6 Decimal places

It is the Code Challenge in internet to get the Ratio of the Positive,Negative,Zero Ratio of an Array elements with 6 decimal places. I solved it but i want to know any other method to solve this problem? And What Means Delegates in C#, I just know about that but not full. Hope you guys helpful! class Result { /* It is the Problem In Interview Question to Calculate the ratio of Positive,Negative,Zero Values in Given Array with 6 Decimal Places*/ /*Example: Take arr={1,1,0,-1,-1} There are n=5 elements, two positive, two negative and one zero. Their ratios are 2/5=0.400000,2/5=0.400000 and 1/5=0.200000 . Results are printed as: 0.400000 0.400000 0.200000*/ public static void plusMinus(List<int> arr) { List<int> p = arr.FindAll(delegate(int a){return a>0;}); //Delegate is used in methods that can be invoke any type of method into return type nor non return List<int> n = arr.FindAll(delegate(int a){return a<0;}); List<int> z = arr.FindAll(delegate(int a){return a==0;}); Console.WriteLine("{0:0.000000}",Convert.ToDouble(p.Count)/Convert.ToDouble(arr.Count)); Console.WriteLine("{0:0.000000}",Convert.ToDouble(n.Count)/Convert.ToDouble(arr.Count)); Console.WriteLine("{0:0.000000}",Convert.ToDouble(z.Count)/Convert.ToDouble(arr.Count)); } } class Solution { public static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine().Trim()); List<int> arr = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(arrTemp => Convert.ToInt32(arrTemp)).ToList(); Result.plusMinus(arr); } } Any other way to solve this in C#?

13th Oct 2021, 2:38 PM
Awizp
2 Réponses
+ 1
Next time, save your code in code playground and share the link here. Copy pasting the whole code results in a clogged question, so people don't want to answer. Try to make your question simple but brief. All the best =)
17th Oct 2021, 5:00 PM
Rishi
0
Rishi Ok Bro, Thanks :)
17th Oct 2021, 6:35 PM
Awizp