Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
There's no harm in doing so if it eventually looks like you're doing something on your own rather than merely bombing forums waiting for some boob to finish your homework.
If you functionize your second chunk of code, it ought to work with a user-entered array. Such a conversion would seem trivial for the work you've already shown.
int mode(int *data, size_t size)
{
/* Mostly copy and paste and changing hard-coded array size. */
}
[edit]Heh. Or just change the loop control:
for(i = 0; i < n; i++) /* for each datum */
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Please use code tags!
When it is only one line of code I usually post them in bold.
Form your second code listing(just changed one value):
int data[] = { 0, 100, 2, 3, 4, 5, 3, 7 }; /* initialise the data array */
What would happen if the following code gets executed and data[i]=100 ?
++freq[data[i]]; /* track the frequency */
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661