/** *************************************************************************** * @remark Program to study a loop with floats * * * * @author Henry M. Walker * * @file float-loop.c * * @date July 24, 2022 * * * * @remark Reference * * @remark Consequences of Data Representation on Programming * https://blue.cs.sonoma.edu/~hwalker/courses/415-sonoma.sp25/readings/data-rep-consequences.php * * *****************************************************************************/ #include int main () { float inc = 1.0/10.0; float val = 0.0; float end = 1.0; float sum = 0.0; printf ("program to loop with floats from %22.15f to %22.15f increment %22.15f\n", val, end, inc); while (val != end) { /* add to sum and print */ sum += val; printf ("val = %22.15f; sum = %22.15f\n", val, sum); /* increment val for loop test and next iteration */ val += inc; } printf ("loop terminated with val = %22.15f; sum = %22.15f\n", val, sum); }