Home > Back-end >  O solve! Be urgent!
O solve! Be urgent!

Time:11-01

Subject to code program, calculates the average scores, the students failed (not less than 60 points) and statistics, the number of questions to ensure the input and output are within the scope of the integer,
The output format:

According to the following format:
Business=average score
Count=pass number

Input the sample:
5
77, 54, 92, 73 60

My code:
# include
Int main ()
{
Int the count, I, n.
Double grade, total business;
The scanf (" % d ", & amp; N);
Total=0;
count=0;
for (i=1; i<=n; I++)
{
Lf the scanf (" % ", & amp; Grade).
Total=total + grade;
If (grade & gt;=60)
{
count++;
Business=total/n.
}
Else if (0 & lt; Grade & amp; & Grade<60)
{
count=0;
Business=total/n.
}
The else
{
Business=0;
count=0;
}

}
Printf (" business=% 1 f \ n ", business);
Printf (" count=% d \ n ", count);
return 0;
}
Why when the input sample count=3? Should not for 4?

CodePudding user response:

 # include & lt; Stdio. H> 
#include
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

# pragma argsused
Int main (int arg c, char * argv [])
{
Int the count, I, n.
Double grade, total business;
Total=0;
count=0;

Printf (" please enter the number of students: ");
The scanf (" % d ", & amp; N);

Printf (" please enter the % d student performance: ", n);
for (i=1; i<=n; I++)
{
Lf the scanf (" % ", & amp; Grade).
Total=total + grade;
If (grade & gt;=60)
{
count++;
}
}
Business=total/n.
Printf (" average score=% 1 f \ n ", business);
Printf (" pass number=% d \ n ", count);

return 0;
}

CodePudding user response:

What is this you write

CodePudding user response:

Why do you count of s? Less than 60?

CodePudding user response:

The
reference UIUI reply: 3/f
why do you count of s? Less than 60?

Because the number count is to pass the orz

CodePudding user response:

refer to the second floor htpidk response:
what you write this

This when n=0 if not

CodePudding user response:

If (n==0)
return 0;

CodePudding user response:

The n input, add the if judgment, modified as follows:
 int the count, I, n. 
Double grade, total business;
Total=0;
count=0;

Printf (" please enter the number of students: ");
The scanf (" % d ", & amp; N);

If (n>
=1){
Printf (" please enter the % d student performance: ", n);
for (i=1; i<=n; I++)
{
Lf the scanf (" % ", & amp; Grade).
Total=total + grade;
If (grade & gt;=60)
{count++; }
}
Business=total/n.
Printf (" gpa business=% 1 f \ n ", business);
Printf (" pass the number count=% d \ n ", count);
}
The else
{printf (" the number of students input error!" ); }

return 0;
  • Related