Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. /*
  2. 利用陣列儲存多筆資料, 計算總分與平均
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #define COUNT 5
  7. int main(){
  8. int scores[COUNT];
  9. int n;
  10. int length = sizeof scores/sizeof scores[0];
  11. int sum=0;
  12. for(n=0; n<length ; n++){
  13. printf("請輸入第%d位學生成績:", n+1);
  14. scanf("%d", &scores[n]);
  15. sum +=scores[n];
  16. }
  17. printf("總分:%d,平均:%d\n",sum,sum/length);
  18. return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement