10370 - Above Average

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10370 - Above Average

Post by brianfry713 »

Next time post in the existing thread.
Only read the number of test cases once.
Check input and AC output for thousands of problems on uDebug!
Sabrina Haque
New poster
Posts: 3
Joined: Fri Jan 23, 2015 9:33 am

Re: 10370 - Above Average

Post by Sabrina Haque »

why getting WA? :(

Code: Select all

#include<stdio.h>

int main()
{
    int C,i,j,count;
    int grade[1002];
    float percentage,sum,avrg_grade,N;

    scanf("%d",&C);

        for(i=0;i<C;i++)
    {
        sum=0;
        count=0;
        avrg_grade=0;

        scanf("%d",&N);

        for(j=0;j<N;j++)
        {
           scanf("%d",&grade[j]);
        }
        for(j=0;j<N;j++)
        {
            sum=sum+grade[j];
        }

        avrg_grade=sum/N;

        for(j=0;j<N;j++)
        {
            if(grade[j]>avrg_grade)
                count++;
            else
                ;
        }

        percentage=(100*count)/N;
        printf("%.3f%%\n",percentage);
    }



    return 0;

}
Last edited by brianfry713 on Tue Jan 27, 2015 12:58 am, edited 1 time in total.
Reason: Added code blocks
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10370 - Above Average

Post by lighted »

Variable N is float, so change

Code: Select all

scanf("%d",&N);
to

Code: Select all

scanf("%f",&N);
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Post Reply

Return to “Volume 103 (10300-10399)”