/* Module: statistics.c
Author: Yana
Date: YEAR/MONTH/DAY
This program reads the grade of each student in class
of num_stud students and computes the following statistics:
1.The number of students that failed ( grade < 60)
2.The average grade of class
3.The average grade of passing students
Input: The number of students num_stud following by
num_stud grades
Output: The number of students that failed, the average grade of class and
and average grade of passing students following by described message.
Algorithm: Read grades while maintaining the number of
failures,
the sum of grades and the sum of grades of passing students
Assumption on input: input contains at least one grade. The grades are integers.
*/
#include < stdio.h >
int main(){
- int num_stud = 0;                         /* The number of students in the class */
- double average = 0.0;                       /* The average grade */
- int num_fail = 0;                        /* The number of students that failed */
- double pass_average = 0.0;                  /* The average grade of passing students */
- int grade = 0;                             /* grade of current student */
- int i = 1;                                 /* serial number of student */
- int sum = 0;                      /* sum of student's grades */
- int sum_pass = 0;                       /* sum of student's passing grades */
- int num_pass = 0;                      /* number of students that passed */
- /* input number of students */
- printf ("Pelase, enter the number if students in your class ");
- scanf ("%d", &num_stud);
- /* Read grades and compute statistics */
- while ( i <= num_stud) {
- printf("Please enter grade of student%d ", i);
- scanf("%d", &grade);
- if (grade < 60)
- else
- sum_pass = sum_pass + grade;      /*update the sum of passing grades */
- sum = sum + grade;       /* update the total sum of all grades */
- i++;
- }
- num_pass = num_stud - num_fail;
- average = (double)sum / num_stud;
- if (num_pass > 0)
- pass_average = (double)sum_pass / num_pass;
- /* output results */
- printf ("in class of %n students the total average is %f, ", num_stud, average);
- printf ("the number of students passed is %d, their average is %f, ", num_pass, pass_average);
- printf ("the number of students failed is %d ", num_fail);
}