1064 Positives and Average

SemiColon
By -
0
URI Online Judge | 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

Solution:

#include<stdio.h>
int main()
{
    double avg=0,total=0,n;
    int i,cnt=0;
    for(i=1;i<=6;i++){
    scanf("%lf",&n);
    if (n>0){
        cnt++;
        total+=n;
    }
  }
      avg=total/cnt;
      printf("%d valores positivos\n",cnt);
      printf("%.1lf\n",avg);

      return 0;

}



Tags:

Post a Comment

0Comments

Post a Comment (0)