URI - BEECROWD - BEE 1064 - Positives and Average Solution in C,C++,Python | URI - BEECROWD - BEE Solution 1064

URI - BEECROWD - BEE 1064 - Positives and Average Solution in C,C++,Python | URI - BEECROWD - BEE Online Judge Solution 1064 - Positives and Average

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 SampleOutput Sample

7
-5
6
-3.4
4.6
12

4 valores positivos
7.4

URI - BEECROWD - BEE 1064 - Positives and Average Solution in C,C++,Python | URI Online Judge Solution 1064 - Positives and Average:

                                        Demonstration:

If any number that represents more than zero of anything then it is called as positive number. For example,15 is a positive number because it's greater than zero.  Zero is called the origin, and it's neither negative nor positive.
First we need to taking all of the inputs by using for loop. We will run for loop until 6 and increment the count and adding the number with sum variable if the given numbers are greater than zero. Then we need to calculate the average by using this formula:
                    Average = Sum/Count
Finally, print the result.

N.B: Don't copy paste the code as same. Just try to understand it and try yourself. It would be better for you.


  URI Problem 1064 Solution in C :   

  URI Online Judge 1064 Solve  in C :                                                                             
#include <stdio.h>
 
int main()
{
    float num,sum=0;
    int i,count=0;
    for(i=1;i<=6;i++){
        scanf("%f",&num);
        if(num>0){
          sum = sum + num;
          count++;
        }
    }
    float average = sum/count;
    printf("%d valores positivos\n",count);
    printf("%.1f\n",average);
    return 0;
}

0 Response to URI - BEECROWD - BEE 1064 - Positives and Average Solution in C,C++,Python | URI - BEECROWD - BEE Solution 1064

Post a Comment