Hello all,
I am new to this forum and C Programming. One of my hw assignments is to write code that returns a value that is repeated more than once in an array of 8 integers.
For example:
Numbers: 30 12 100 33 2 2 1 40
Output: 2
Here is my code so far:
When I compile this code (on Vim), I get an error when I print the array of 8 above (see ERROR above).Code:#include <stdio.h> int main(void){ int i; int j; int arr[8]; int count; int maxCount = 0; int maxValue = 0; printf("Enter 8 values between 1-100: "); for(i = 0; i < 8; i++){ scanf("%d", arr[i]); /* ERROR */ } for(j = 0; j < 8; j++){ count = 0; for(i = 0; i < 8; i++){ if(arr[i] == arr[j]){ count++; } if(count > maxCount){ maxCount = count; } } maxValue = arr[i]; } printf("Number: %d", maxValue); }
Thanks for your help.



LinkBack URL
About LinkBacks



