> 其他 >
如何用C语言求平均数?输入数据个数不定!
我要求不需要输入数字个数啊...
人气:334 ℃ 时间:2020-05-27 08:30:19
解答
#include
int fun1(int b[])
//计算输入数据的个数
{
int i,count=0;
for(i=0;b[i]!='\0';i++)
count++;
return count;
}
double fun2(int c[],int count)
//求平均值并输出结果
{
int i;
double sum=0.0;
for(i=0;c[i]!='\0';i++)
sum+=(double)c[i];
printf("您输入了%d个数据/n平均值为%lf",count,sum/(double)count);
}
main()
{
int a[SIZE],i=0,count;
do
{
scanf("%d",&a[i]);
i++;
}while(a[i-1]!='\0')
count=fun1(a);
fun2(a,count);
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版