Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Why is the average value of C language always 0? The code is as follows: # include

You can define sum 1 as a float, or you can force type conversion by setting aver1= (float) sum1/3.

int a

Why is the average value of C language always 0? The code is as follows: # include

You can define sum 1 as a float, or you can force type conversion by setting aver1= (float) sum1/3.

int a

Why is the average value of C language always 0? The code is as follows: # include

You can define sum 1 as a float, or you can force type conversion by setting aver1= (float) sum1/3.

int a[3]={80,60,90 };

Floating point aver1;

float sum 1 = a[0]+a[ 1]+a[2];

aver 1 = sum 1/3;

Printf ("The average score of student 1 is %f", Aver1);

printf(" \ n ");

or

int a[3]={80,60,90 };

Floating point aver1;

int sum 1 = a[0]+a[ 1]+a[2];

aver 1 =(float)sum 1/3;

Printf ("The average score of student 1 is %f", Aver1);

printf(" \ n ");