Originally Posted by
Daved
What's your best idea?
I set the 'a' value and set a condition.But, this only calculate the average for the particular condition only.E.g: If I set a==60,then it will print average of 'b' if a==60. It did not work if there is multiple condition.
p/s: 'a' actually is the angle between 0 to 90 degrees.
Here is the sample of the code:
Code:
for(i=0;i<n;i++){
fscanf(fin,"%f,%f\n",&a[i],&b[i]);
}
for(i=0;i<n;i++){
if (a[i]==60){
k=k+1;
sum=sum+b[i];
}
}
printf("%.1f\n",sum/k);
or something like this:
Code:
while (!feof(fin)){
fscanf(fin,"%f,%f\n",&a,&b);
if (a==60){
sum=sum+b;
k=k+1;
printf("%.1f\n",sum/k);
}
}