Header Ads

Header ADS

Solution of URI 1154::Ages

Before seeing the solution make sure that you have tried enough. Don’t copy the whole code, just find out the logic. If you feel any problemyou will inform me by comment.




#include <stdio.h>
int main() {
    int age,t_age=0,count=0;
    float avg_age;

    while(1) {
        scanf("%d",&age);
        if(age>=0) {
            t_age += age;
            count++;
        }
        else
            break;
    }

    avg_age = (float) t_age/count;
    printf("%.2f\n",avg_age);

    return 0;
}

No comments

Theme images by konradlew. Powered by Blogger.