#include <stdio.h>
#include <stdlib.h>
int main(int argc,char **argv)
{
double sum=0.0,aver=0.0;
int start,step,num;
printf("请输入起始值,步长,元素个数(a,b,c):");
scanf("%d,%d,%d",&start,&step,&num);
printf("start = %d,step = %d,num = %d\n",start,step,num);
int i;
for(i=0;i<num;i++)
sum=sum+start+i*step;
aver=sum/num;
printf("sum is %f\n",sum);
printf("aver is %f\n",aver);
system("pause");
return 0;
}
实例22 计算数列的平均数
最新推荐文章于 2024-01-08 21:47:57 发布