第9.1 小节代码 计算平均值
//This is a comment
//Author:King
//Time:2020/12/6
//Reference:C Programming:A Modern Approach,Second Edition
/***************************************************************
9.1 小节代码 显示平均数
****************************************************************/
#include <stdio.h>
//#include <stdbool.h> // C99 only
//#include <time.h>
//#include <stdlib.h>
double average(double a, double b)
{
return (a + b) / 2;
}
int main(void)
{
double x, y , z;
printf("Enter three numbers:");
scanf("%lf%lf%lf",&x,&y,&z);
printf("Average of %g and %g is %g\n",x,y,average(x,y));
printf("Average of %g and %g is %g\n",x,z,average(x,z));
printf("Average of %g and %g is %g\n",y,z,average(y,z));
system("pause"); //加入该函数后可以使得产生的exe单独运行,不会发生闪退。也可以加入其它函数使得main函数无法返回即可。如while(1)、getchar() 等
return 0;
}