Algorithm


Problem Name: beecrowd | 1064
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1064

Positives and Average

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

Read 6 values that can be floating point numbers. After, print how many of them were positive. In the next line, print the average of all positive values typed, with one digit after the decimal point.

Input

The input consist in 6 numbers that can be integer or floating point values. At least one number will be positive.

Output

The first output value is the amount of positive numbers. The next line should show the average of the positive values ​typed.

Input Sample Output Sample

7
-5
6
-3.4
4.6
12

4 valores positivos
7.4

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>

int main(){      
    float n1,total = 0,average = 0;
    int totalNumber = 0;
    
    for (int i = 1; i  < = 6; i++) {
        scanf("%f", &n1);
        if (n1 > 0) {
            totalNumber += 1;
            total += n1;
        }
    }
    average = total / totalNumber;
    
    printf("%d valores positivosn", totalNumber);
    printf("%.1fn",average);
    
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
7 -5 6 -3.4 4.6 12

Output

x
+
cmd
4 valores positivos 7.4

#2 Code Example with C++ Programming

Code - C++ Programming


#include <cstdio>
int main()
{
    double n, ctr = 0;
    double tmp = 0;
    
    for(int i = 0; i  <  6; ++i)
    {
    scanf("%lf", &n);
    if(n > 0) {
            tmp += n;
            ctr++;
        }
    }
    
    printf("%.0lf valores positivosn%.1lfn", ctr, tmp/ctr);
    
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
7 -5 6 -3.4 4.6 12

Output

x
+
cmd
4 valores positivos 7.4

#3 Code Example with Java Programming

Code - Java Programming


import java.io.IOException;
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) throws IOException {
        float n1,total = 0,average = 0;
        int totalNumber = 0;
        Scanner sc =new Scanner(System.in);
            for (int i = 1; i  < = 6; i++) {
            n1 =sc.nextFloat();
            if (n1 > 0) {
                totalNumber += 1;
                total += n1;
            }
        }
        average = total / totalNumber;

        System.out.print(totalNumber+" valores positivosn");
        System.out.printf("%.1fn",average);

    }
 
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
7 -5 6 -3.4 4.6 12

Output

x
+
cmd
4 valores positivos 7.4
Advertisements

Demonstration


Previous
#1062 Beecrowd Online Judge Solution 1062 Rails - Solution in C, C++, Java, Python and C#
Next
#1065 Beecrowd Online Judge Solution 1065 Even Between five Numbers - Solution in C, C++, Java, Python and C#