Re: [問題] C語言運算式的問題~

看板TransCSI作者 (小葉子)時間18年前 (2007/08/13 19:54), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/2 (看更多)
Problem-1: Input three integer scores and their corresponding weights, display the Maximum and the Minimum scores among them, and print out their weighted average value. #include<stdio.h> #define NUM 3 main(){ int score[NUM],weight[NUM],max,min,i,t_weight=0,t_score=0; for(i=0;i<NUM;i++){ printf("Please input the number %d score: ",i+1); scanf("%d",&score[i]); printf("Please input the number %d weight: ",i+1); scanf("%d",&weight[i]); if(i==0) max=min=score[0]; if(score[i]>max) max=score[i]; if(score[i]<min) min=score[i]; t_weight = t_weight + weight[i]; t_score = t_score + (score[i] * weight[i]); } printf("Maximum: %d\n",max); printf("Minimum: %d\n",min); printf("Average: %d\n",t_score/t_weight ); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.164.74.16

08/13 20:33, , 1F
謝謝你了~~
08/13 20:33, 1F
文章代碼(AID): #16m4PbVf (TransCSI)
文章代碼(AID): #16m4PbVf (TransCSI)