tom19960222

及格不及格_各種成績相關計算

Oct 22nd, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. /* 懶得多寫一個版本了 把每個要算的都寫出來了*/
  2. #include <stdio.h>
  3.  
  4. int main ()
  5. {
  6.     int num, failed_count=0, total_count=0, score[100], failed_sum=0, passed_sum=0;
  7.    
  8.     printf ("Please input scores (-1 to exit): ");
  9.    
  10.     while (1)
  11.     {
  12.         scanf ("%d", &num);
  13.         if (num == -1) break;
  14.         if (num < 60)
  15.         {
  16.             score[failed_count] = num;
  17.             failed_count++;
  18.             failed_sum += num;
  19.         }
  20.         else
  21.             passed_sum += num;
  22.         total_count++;
  23.     }
  24.    
  25.     printf ("There are %d people in total, %d people failed, %d people passed.\n", total_count, failed_count, total_count-failed_count);
  26.     printf ("The average score of failed people is %.2f, passed people is %.2f, all people is %.2f", (float)failed_sum/failed_count, (float)passed_sum/(total_count-failed_count), (float)(failed_sum+passed_sum)/total_count);
  27.    
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment