Plus Minus | Hacker Rank



My Solution:
 

public static void plusMinus(List<int> arr)

    {
        //Console.Write(arr.Count);
        var n = arr.Count;
        float plus =0, minus=0,zero=0;
        foreach(var item in arr){
            if(item == 0){
                zero++;
            }
            if(item>0){
                plus++;
            }
            if(item<0){
                minus++;
            }
        }
        float dPlus, dMin, dZero;
        dPlus = plus/n;
        Console.WriteLine(Math.Round(dPlus,6));
        
        dMin = minus/n;
        Console.WriteLine(Math.Round(dMin,6));
        
        dZero = zero/n;
        Console.WriteLine(Math.Round(dZero,6));
    }

No comments:

Post a Comment

Starting My journey as Mobile Developer

 Hi there! Today, I started my journey as a mobile developer, after years of working as a software engineer. Now I want to open a new page i...