We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Plus Minus
- Discussions
Plus Minus
Plus Minus
Sort by
recency
|
279 Discussions
|
Please Login in order to post a comment
C++11
/* * Complete the 'plusMinus' function below. * * The function accepts INTEGER_ARRAY arr as parameter. */
void plusMinus(vector arr) { float positive = 0, negative = 0, zero = 0; int total = arr.size();
}
Scala
!/bin/python3
import math import os import random import re import sys
#
Complete the 'plusMinus' function below.
#
The function accepts INTEGER_ARRAY arr as parameter.
#
def plusMinus(arr): pos_num = 0 neg_num = 0 zero_num = 0
iterate over array
Calculate totals
Print totals
if name == 'main': n = int(input().strip())
This is the Java code
public static void plusMinus(List arr) { // Write your code here int len=arr.size(); float posCount=0; float negCount=0; float zeroCount=0; for(int i = 0; i < len ; i++) { int elements = arr.get(i); if(elements>0){ posCount++; } else if(elements<0){ negCount++; } else{ zeroCount++; } } System.out.printf("%.6f%n",posCount/len); System.out.printf("%.6f%n",negCount/len); System.out.printf("%.6f%n",zeroCount/len);
}