Sort by

recency

|

3233 Discussions

|

  • + 0 comments
    void plusMinus(vector<int> arr) {
    	int p = 0, n = 0, z = 0;
    	for(int el : arr){
    		if(el > 0) 
    			p++;
    		else if(el < 0) 
    			n++;
    		else 
    			z++;
    	}
    	double total = arr.size();
    	double pr = p / total;
    	double nr = n / total;
    	double zr = z / total;
    
    	// Set the output to print 6 decimal places
    	cout << fixed << setprecision(6);
    	// Print each result on a new line
    	cout << fixed << setprecision(6);
    	cout << pr << "\n" << nr << "\n" << zr;
    }
    
  • + 0 comments

    Rust:

    fn plusMinus(arr: &[i32]) {
        let mut pos: f32 = 0.0;
        let mut neg: f32 = 0.0;
        let mut zer: f32 = 0.0;
        let all = arr.len() as f32;
        
        for &i in arr {
            match i {
                i if i > 0 => pos += 1 as f32,
                i if i < 0 => neg += 1 as f32,
                i => zer += 1 as f32,
            }
        }
        println!("{}", pos / all);
        println!("{}", neg / all);
        println!("{}", zer / all);
    }
    
  • + 0 comments

    JS:

    function plusMinus(arr: number[]): void {
        // Write your code here
        let pos = 0;
        let neg = 0;
        let zer = 0;
        let all = arr.length;
        
        for (const num of arr) {
            switch (true) {
                case num > 0: pos++; break;
                case num < 0: neg++; break;
                default: zer++;
            }
        }
        
        console.log(pos / all);
        console.log(neg / all);
        console.log(zer / all);
    }
    
  • + 0 comments

    int s = arr.size(); float posi = 0.0f; float nega = 0.0f; float zero = 0.0f; for(int i=0; i0){ posi = posi+1; } else if(arr.get(i)<0){ nega = nega+1; } else{ zero = zero+1; }

    }
    float a =(float) (posi/s);
     System.out.printf("%.6f%n",a);
     float b =(float) (nega/s);
     System.out.printf("%.6f%n",b);
     float c =(float) (zero/s);
     System.out.printf("%.6f%n",c);
    
  • + 0 comments

    I absolutely love this theme idea — it looks stunning and very appealing! I’m planning to use it for my ecommerce-based store, mens compression socks, which is hosted on Shopify