I'm having a bit of an issue with my my program - i would like it to count the number of times a certain integer (between 0-9) has been input by the user. I'm using mainly arrays/loops to do so, however it feels like im just going round in circles ... i know im missing something vital here. Anyway, my code looks like this at the moment:
#include <stdio.h>
int main(int argc, char *argv[]) {
int arr[10] = {0};
int i=0;
int x=0;
printf("Enter ten integers:\n");
for (i=0; i<10; i++) {
x = scanf("%d", &i);
}
for (i=0; i<10; i++) {
printf("%d seen %d times\n", i, arr[x]);
}
return 0;
}
An example of output:
Enter ten integers:
1 2 3 4 5 0 0 9 8 7
0 seen 0 times
1 seen 0 times
2 seen 0 times
3 seen 0 times
4 seen 0 times
5 seen 0 times
6 seen 0 times
7 seen 0 times
8 seen 0 times
9 seen 0 times
Any help is well appreciated,
Thanks,
John =)


Sign In
Create Account

Back to top









