Friday, October 26, 2018

Uri 1064 solution in C | Positives and Average

/*Before seeing the code solution make sure that you have tried enough. Don’t copy- paste the whole code. Find out the logic. If you face any trouble, just inform me in comment.*/

#include<stdio.h>
main()
{
    int i,c=0;
    float s=0,a,n;
    for(i=0;i<6;i++)
    {
        scanf("%f",&n);

        if(n>0)
        {
            s=s+n;
            c++;
        }
    }

    a=s/c;
    printf("%d valores positivos\n",c);
    printf("%.1f\n",a);
    return 0;
}

 //Happy_Coding

No comments:

Post a Comment