1064 - Positives and Average

Problem Link


A Solution in c



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





No comments

Theme images by Jason Morrow. Powered by Blogger.