/* Program: rolled.c This program finds the smallest and average values of a list of numbers entered by the user. The end of the list is indicated by entering a 0. This program was developed using the loop unrolling process. */ #include #include "genlib.h" #include "simpio.h" #define SENTINNEL 0 main() { int value, total, minimum, items ; double average ; printf("Signal end of list with a 0.\n") ; /* Get first number */ printf(" ? ") ; total = 0 ; items = 0 ; value = GetInteger() ; /* Check if the first number is zero */ if (value == 0) { printf("No items were entered.\n") ; } else { /* Initializing variables */ total = value ; items = 1 ; minimum = value ; printf(" ? ") ; value = GetInteger() ; while (value != SENTINNEL) { total += value ; items++ ; if (value < minimum) minimum = value ; printf(" ? ") ; value = GetInteger() ; } /* Report the results */ printf("Total value: %d.\n", total) ; printf("Smallest value: %d.\n", minimum) ; average = ((double) total) / ((double) items) ; printf("Average value: %f.\n", average) ; } }