I am having floating point exception in the following code .
int heavy_decimal_count ( int A, int B )
{
char * markup = "Heavy";
int i , value;
int tempA = A;
int tempB = B;
int reminder = 0;
int sum = 0;
float average = 0.00;
int counter = 0;
if( (tempA < 0) || ( tempB <0 )||( B < A ) )
{
printf(" Error -> Numbers are negative or B is less than A");
return 0;
}
for ( i = A ; i <= B ; i++)
{
value = i;
while( value > 0 )
{
printf(" the value is %d ", value );
counter += counter;
reminder = value % 10;
value /= 10;
sum += reminder;
average = sum/counter ;
}
if( average > 7.0 )
printf(" %d \t avg= %f\t %s\t" ,i , average , markup);
else
printf(" %d \t avg=%f\t " ,i , average );
}
return 0;
}
Despite the name, a “floating point exception” actually happens when you
/or%an integer by0. My guess is that it happens here:because
counteris still0. I think you meantto be
Also, you might want to change the division to
so it can happen as a fraction value rather than an integer.