/* File: input3.c Have the user type in a bunch of numbers */ #include #define MAX_SIZE 20 int main() { int i, n, r ; double average, num ; // declare and initialize array int A[MAX_SIZE] ; printf("Enter your numbers. End with ctrl-D.\n") ; n = 0 ; i = 0 ; while (1) { printf("A[%d] = ", i) ; r = scanf("%d", &A[i] ) ; if ( r <=0 ) { printf("The end reached.\n") ; break ; } i = i + 1 ; if (i >= MAX_SIZE) { printf("No more numbers!!\n") ; break ; } } n = i ; printf("n = %d\n", n) ; int sum = 0 ; for (i = 0 ; i < n ; i++) { sum = sum + A[i] ; } num = n ; // num is double average = sum / num ; printf ("The average value entered is: %f\n", average) ; return 0 ; }