程式1:
#include
int main()
{
int i;
float num;
float sum = 0;
i = 10;
while(i--)
scanf("%f",&num);
sum += num;
}
sum /= 10.0;
printf("輸入的十個數的平均數為: %f",sum);
getch();
return 0;
思考:
int i,amount;
printf("請輸入資料的總個數\n");
scanf("%d",&amount);
printf("請依次輸入%d個數據.\n",amount);
i = amount;
sum = sum / (amount / 1.0);
printf("輸入的%d個數的平均數為: %f \n",amount,sum);
程式1:
#include
#include
int main()
{
int i;
float num;
float sum = 0;
i = 10;
while(i--)
{
scanf("%f",&num);
sum += num;
}
sum /= 10.0;
printf("輸入的十個數的平均數為: %f",sum);
getch();
return 0;
}
思考:
#include
#include
int main()
{
int i,amount;
float num;
float sum = 0;
printf("請輸入資料的總個數\n");
scanf("%d",&amount);
printf("請依次輸入%d個數據.\n",amount);
i = amount;
while(i--)
{
scanf("%f",&num);
sum += num;
}
sum = sum / (amount / 1.0);
printf("輸入的%d個數的平均數為: %f \n",amount,sum);
getch();
return 0;
}