/* Program Title: lab8_jumpstart * Author: Slobodan Vucetic * Date: 10/19/2006 * * Requirements: * Ask a user to enter up to 20 nonnegative integers. * If user enters a negative number, stop the entering process. * After user enters 20 numbers, stop the entering process. * Calculate sum of all entered numbers * Calculate average of all entered numbers * Find the smallest entered number * * Test Plan: * Test by entering several different combinations of integers. * Check if entering a negative number stops the entering process * Check if the entering process is stopped after user enters 20 numbers * Check if the results are correct */ /* Preprocessor directives */ #include /* Main function */ int main(void) { int scores[20]; int I, flag; int array_size, array_sum, array_avg, array_min; /* A procedure for populating the array */ i = 0; flag = 0; do { printf(“\n Enter an integer >= 0 (if integer < 0, stop)> “); scanf(“%d”,&scores[i]); printf(“... you entered %d”, scores[i]); if (scores[i] > 0) i = i+1; else flag = 1; } while(i < 20 && flag == 0); array_size = i; printf(“\n\n***Size of the array is %d”, array_size); /* A procedure that sums all entered integers */ array_sum = 0; for (i=0; i < array_size; i = i+1) array_sum = array_sum + scores[i]; printf(“\n*** Sum of array elements is %d”, array_sum); /* Calculate the average of the entered integers */ array_avg = array_sum/array_size; printf(“\n***Average of the array elements is %d”, array_size); /* Find the smallest entered integer */ array_min = scores[0]; for (i=1; i < array_size; i++) { if (scores[i] < array_min) array_min = scores[i]; } printf(“\n***The smallest element of the array is %d \n\n”, array_min); return(0); }