#include<stdio.h>
#include<stdlib.h>
int main(){
int a,b,c;
double average,total;
printf("請輸入第一個整數? ");
scanf("%d",&a);
printf("請輸入第二個整數? ");
scanf("%d",&b);
printf("請輸入第三個整數? ");
scanf("%d",&c);
total=a+b+c;
average=total/3;
printf("%d+%d+%d=%d\n",a,b,c,total);
printf("平均數為%.2f",average);
system("pause");
return 0;
}
printf("%d+%d+%d=%d\n",a,b,c,total);
回覆刪除這行好像要改成
printf("%d+%d+%d=%.0f\n",a,b,c,total);
才能正確顯示出~
對,你說的沒錯。因為我total是宣告成雙浮點數,所以要用%f,謝謝指正!
回覆刪除