Wednesday, December 2, 2015

Uri problem 1064 solve

Problem :

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 point floating 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 thepositive values ​typed.
Sample InputSample Output
7
-5
6
-3.4
4.6
12
4 valores positivos
7.4

Solution:

#include<stdio.h>
 
int main()
{
    int  i  ,sum ;
    float inp[6], avrg , total;
    for(i = 0; i < 6; i++)
        scanf("%f",&inp[i]);
        sum = 0;
        total = 0;
        for(i = 0; i < 6; i++){
            if(inp[i] >= 0){
                sum = sum + 1;
                total = total + inp[i];
            }
        }
        avrg = total / sum;
        printf("%d valores positivos\n",sum);
        printf("%.1f\n",avrg);
 
    return 0;
}

No comments:

Post a Comment