im trying to get a good understanding of arrays and have run into a few problems, just a few minor pieces of code im missing probally.
i want to write a program that lets me scanf numbers into the array and exit if they enter a negative number. then find the average of the numbers i did enter.
i tried to use a function for the average portion but i couldnt get it work, and the average system i have set up know does not work at all... perhaps there is a way to leave the
open so i dont have extra 0's and adding to the total sum to divide by at the end process if the program terminates early.Code:int numbers[10];
here is my code so far
and the average is wrong i cant make it calculate correctly...Code:#include <stdio.h> int main() { int numbers[10]; int i; int count = 10; int sum = 0; double average; printf("\nEnter the numbers:\n"); for(i = 0; i < count; i ++) // scanf into the array--- { printf("%2d> ",i+1); scanf("%d", &numbers[i]); if(numbers[i]<0){ break;} } for(i=0; i<10; i++){ sum += numbers[i]; // to keep up with the total after each input } average = sum/numbers[i]; printf("the mean is: %lf ", average); return 0; }