该程序正在计算整数平均值而不打印十进制值。它将结果打印为整数:N.000000。为什么?
//Store name, roll no, marks of 4 students using structure
//and calculating average
struct student
{
char name[10];
int roll_no;
int marks;
};
void main()
{
struct student s1,s2,s3,s4;
float avg;
clrscr();
printf("\nEnter name, rollnumber and marks of student 1 : \n");
scanf("%s%d%d",&s1. name,&s1. roll_no,&s1. marks);
printf("\nEnter name, rollnumber and marks of student 2 : \n");
scanf("%s%d%d",&s2. name,&s2. roll_no,&s2. marks);
printf("\nEnter name, rollnumber and marks of student 3 : \n");
scanf("%s%d%d",&s3. name,&s3. roll_no,&s3. marks);
printf("\nEnter name, rollnumber and marks of student 4 : \n");
scanf("%s%d%d",&s4. name,&s4. roll_no,&s4. marks);
avg = (s1. marks + s2. marks + s3. marks + s4. marks) / 4;
printf("\nAverage : %f",avg);
getch();
}