C语言 为什么浮点错误了?求平均值的
#include<stdio.h>intmain(intargc,char*argv[]){intx,i,y,a=0,b=0,c=0,d=0;//c为奇数个,d为偶素个d...
#include <stdio.h>
int main(int argc, char *argv[])
{
int x,i,y,a=0,b=0,c=0,d=0;//c为奇数个,d为偶素个
double av1=0.00,av2=0.00;av1是奇数均值av偶数均值
scanf("%d",&i);
while(i--){
scanf("%d",&x);if(x==0)break;
if(x%2==0){b+=x;d++;
}
else {a+=x;c++;}
}
av1=a/c;av2=b/d;
//printf("%d %d\n",a,b);
printf("av1=%.2lf,av2=%.2lf",av1,av2);
return 0;
} 展开
int main(int argc, char *argv[])
{
int x,i,y,a=0,b=0,c=0,d=0;//c为奇数个,d为偶素个
double av1=0.00,av2=0.00;av1是奇数均值av偶数均值
scanf("%d",&i);
while(i--){
scanf("%d",&x);if(x==0)break;
if(x%2==0){b+=x;d++;
}
else {a+=x;c++;}
}
av1=a/c;av2=b/d;
//printf("%d %d\n",a,b);
printf("av1=%.2lf,av2=%.2lf",av1,av2);
return 0;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询