Saturday 6 February 2016

Solution of URI 1064 :: Positives and Average


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    double a,b=0,c;
    int x,y=0;
    for(x=1;x<=6;x++)
    {
        scanf("%lf", &a);
        if(a>=0)
        {
            y++;
            b+=a;
        }
    }
    c=b/y;
    printf ("%d valores positivos\n",y);
    printf("%.1lf\n", c);
    return 0;
}

2 comments:

Note: only a member of this blog may post a comment.