看板 TransCSI 關於我們 聯絡資訊
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
ssnn:謝謝你了~~ 08/13 20:33