Здесь два набора кодов, кажется, не отличаются друг от друга, но один из них генерирует предупреждения и ошибки сегментации 11.
//the program which turns out alright
#include<stdio.h>
int main()
{int a,b,c,d;float f;
scanf("%d %d %d",&a,&b,&c);
d=a+b+c;
f=(a+b+c)*1.0/3.0;
printf("%d %.2f\n",d,f);
return 0;
}
//the program that comes along small issues
//format specifies type 'int *' but the argument has type 'int' [-Wformat]
//After inputting 3 integers, in mac terminal console, it showed: segmentation fault:11
#include<stdio.h>
int main(void)
{
int a,b,c = 0;
float average = 0.0f;
printf("Please enter three integers you wish to calculate their average:");
scanf("%d %d %d", a,b,c); //从input把数据放到arithmatic counter里面
average = (float)(a+b+c)/3.0f;
printf("\nThe average of the three numbers is:%.2f", average);
return 0;
}