//#include "stdafx.h"//If the vc++6.0, with this line. #include "stdio.h" int main(void){ float a=123.456789111f,b=4.5020000f; printf("通常输出:%f %f\n",a,b); printf("紧凑输出:%g %g\n",a,b); return 0; }
因为这里的sum1被你定义成整形了 aver1=sum1/3,右边是整形 左边是浮点型 所以不行 你可以把sum1定义为float 也可以将aver1=(float)sum1/3, 强制类型转换 int a[3]=; float aver1; float sum1=a[0]+a[1]+a[2]; aver1=sum1/3; printf("the average score of student1 are %f",aver1); printf("\n"); 或者 int a[3]=; float aver1; int sum1=a[0]+a[1]+a[2]; aver1=(float)sum1/3; printf("the average score of student1 are %f",aver1); printf("\n");