#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
double a;
int x,z,b;
scanf("%d",&x);
z = x;
a = 1;
b = 0;
while (x != -1){
a += 1;
scanf("%d",&x);
z += x;
printf("a=%f,z=%d,b=%d",a,z,b);
}
b = z / a;
printf("%f\n",1.0*z/a);
}
这是运行结果
2
3
a=2.000000,z=5,b=04
a=3.000000,z=9,b=05
a=4.000000,z=14,b=0-1
a=5.000000,z=13,b=02.600000
Process exited after 38 seconds with return value 9
请按任意键继续. . .