Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Monday, 14 November 2016

URI-1064

URI Online Judge | 1064

Positives and Average

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link Click here
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()
{
    int count=0,n=0;
    float a,res,sum=0;
    while(n!=6){
        scanf("%f",&a);
        if(a>=0){
            count++;
            sum=sum+a;
        }
        n++;
    }
    res=sum/count;
    printf("%d valores positivos\n",count);
    printf("%.1f\n",res);
    return 0;
}

No comments:

Post a Comment