## 10370 - Above Average

Moderator: Board moderators

sv90
New poster
Posts: 17
Joined: Wed Feb 01, 2006 8:27 pm

HERE IS MY CODE I GOT WA WHY
i remove my code
Last edited by sv90 on Sun Feb 05, 2006 10:48 am, edited 1 time in total.

Wei-Ming Chen
Experienced poster
Posts: 122
Joined: Sun Nov 13, 2005 10:25 am
Location: Taiwan
for(k=0;k<=n;k++)
{
if(a[k]>av)
{
count++;
}
}

k<=n??
I thought is k<n

sv90
New poster
Posts: 17
Joined: Wed Feb 01, 2006 8:27 pm

sv90 wrote:HERE IS MY CODE I GOT WA WHY
thanks

mek027
New poster
Posts: 3
Joined: Sat Feb 11, 2006 4:05 pm

### 10370 WA?! why?

i got WA plz help me
this is my code :
#include<stdio.h>
int main()
{
double ave,p,sum=0;
scanf("%d",&tc);
while(tc)
{
p=0.000;sum=0.000;c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
}
ave=((double)sum/(double)n);
for(i=0;i<n;i++)
{
c++;
}
p=(((double)c*(double)100)/(double)n);
printf("%.3lf%%\n",p);
tc--;

}
return 0;
}

wook
Learning poster
Posts: 76
Joined: Fri Oct 01, 2004 11:34 am
Location: Korea, Republic Of
i think there was a precision error....

since a is integer, sum is integer, too.

the code

Code: Select all

``````ave=((double)sum/(double)n);
for(i=0;i<n;i++)
{
c++;
} ``````
is proabably making a trivial error!

the inequation

is equal to

for n is positive.

In this way, you use no real-valued variant,
i.e. using ONLY INTEGER VARIANTS -- without precision errors,
you can get a correct answer, I tink.
Sorry For My Poor English.. mek027
New poster
Posts: 3
Joined: Sat Feb 11, 2006 4:05 pm
hello
i do your offers but still give WA

mek027
New poster
Posts: 3
Joined: Sat Feb 11, 2006 4:05 pm

### 10370

plz give me some I/O for 10370(above average)
Tx alot

goodluck
New poster
Posts: 1
Joined: Wed Jul 26, 2006 8:43 pm

### 10370 Compile Error :-(

i think it's very easy,but...
this is my code,can anybody tell me why?

#include<stdio.h>
int main()
{
int sum=0;
int a;
int i,j,k,c;
scanf("%d",&i);
for(k=0;k<i;k++)
{
scanf("%d",&j);
for(k=0;k<j;k++)
{
scanf("%d",&a[k]);
sum+=a[k];
}
c=0;
for(k=0;k<j;k++)
{
if(a[k]>float(sum/j)) c++;
}
printf("%.3f%%\n",(float)c/j*100);
}
return 0;
}

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:
I think it is because you defined variable k inside k... I changed your code a bit

Code: Select all

``````#include<stdio.h>
int main()
{
int sum=0;
int a;
int i,j,k,c,z;
scanf("%d",&i);
for(k=0;k<i;k++)
{
scanf("%d",&j);
for(z=0;z<j;z++)
{
scanf("%d",&a[z]);
sum+=a[z];
}
c=0;
for(z=0;z<j;z++)
{
if(a[z]>float(sum/j)) c++;
}
printf("%.3f%%\n",(float)c/j*100);
}
return 0;
}

``````
but I think this will give you runtime error because you defined size of array a only 100... you should add the size of array a also...

Hope it helps... sobuz
New poster
Posts: 4
Joined: Mon Aug 21, 2006 2:41 pm

### 10370(restircted function error)

#include<stdio.h>
int main()
{
float avg,percent,t;

scanf("%lu\n",&ca);
for(index=1;index<=ca;index++)
{
scanf("%lu\t",&n);
if(n<=1000)
{
for(p=1;p<=n;p++)
{
avg=sum/n;
}
for(p=1;p<=n;p++)
{
count++;

}
t=(float)count/n;
percent=t*100;
printf("%.3f%\n",percent);
count=0;
sum=0;
percent=0;
}
}

return;
}

kolpobilashi
Learning poster
Posts: 54
Joined: Mon Jan 02, 2006 3:06 am
Contact:
since your return type in main() function is int so you need to return a value.so change your code to:

Code: Select all

``return 0;``
and you should print a % after each output according to the problem's output format, but your code fails to print this.chage your code

Code: Select all

``printf("%.3f%\n",percent); ``
to:

Code: Select all

``printf("%.3f%c\n",percent,'%');``
hope u'll get AC Sanjana

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:
Will any one rell me where is the problem??
Here is my code:#include<stdio.h>

int main()
{
int a,num,i,j,k,az,stu;
double sh,ave,kl,al;

while(scanf("%d",&num)==1)
{
for(i=0;i<num;i++)
{
scanf("%d",&a);
ave=0;az=0;kl=0;al=0;
for(j=0;j<a;j++)
{
scanf("%d",&stu[j]);
ave+=stu[j];
}
ave/=a;
k=0;az=0;
az=(int)ave;
for(j=0;j<a;j++)
{
if(stu[j]>az)
k++;
}
kl=(float)k;
al=(float)a;
sh=(kl/al);

printf("%.3lf%\n",sh*100);
}

}

return 0;
}

jesun
New poster
Posts: 10
Joined: Tue Jan 01, 2008 10:55 pm

I can't figure out the bug in my solution to problem no 10370?Could anyone help me? And sorry for opening a new thread although there is one because I didn't know about that rule/request.i hope I shall not do this in coming future.
here is my code:

Code: Select all

``````#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
#include <stdio.h>
//#include <conio.h>

int main()
{
int m,n,i,j;
float result=0.000;

cin>>n;
while(n)
{
cin>>m;
if(m==0)
{
printf("0.000");
cout<<"%"<<endl;
n--;
continue;
}
vector<int> record(m);
j=0;
for(i=0;i<m;i++)
{
cin>>record[i];
}
if(m==1)
{
printf("0.000");
cout<<"%"<<endl;
n--;
continue;
}
for(i=0;i<m;i++)
{
result+=record[i];
}
result=result/m;

for(i=0;i<m;i++)
{
if(record[i]>result)
{
j++;
}
}
result=(float)j/(float)m;
printf("%.3f",result*100.000);
cout<<"%"<<endl;
n--;
}
//getch();
return 0;
}``````

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

### 10370

Some one plezzzzzz help me this program is calculating for the first input but not working for the next inputs.....

Code: Select all

``````#include<stdio.h>
int main()
{
long int n,x,i,m;
long double sum,ave,ans,count;
while(scanf("%ld",&m)==1)
{
for(i=1;i<=m;i++)
{

scanf("%ld",&n);
for(i=1;i<=n;i++)
{
scanf("%ld",&x[i]);
}
sum=0;
for(i=1;i<=n;i++)
{
sum=sum+x[i];
}
ave=0;
ave=sum/n;
count=0;
ans=0;
for(i=1;i<=n;i++)
{
if(x[i]>ave)
count++;
}
ans=(count/n)*100;
printf("%.3Lf%%\n",ans);
}
}
return 0;
}``````
try_try_try_try_&&&_try@try.com
This may be the address of success.

DanielMarques
New poster
Posts: 5
Joined: Thu Jan 24, 2008 7:13 pm
Location: Rio de Janeiro
No need for the while loop:

Code: Select all

``````long int n,x,i,m;
long double sum,ave,ans,count;
scanf("%ld",&m);
for(i=1;i<=m;i++)
{
...
``````
One more thing, you're already using 'i' as the count in the first for loop, so you must choose a different variable in the other for's.