Hey i really need help figuring out how to tally up the frequency of a value in an array, here are the instructions for the program:
http://www.cs.ucf.edu/~riqbal/assign5.html
I would really appreciate it if someone could tell me how to figure out how to count the number of times that the number appears:
#include <stdio.h>
#define SIZE 8
int sort(int);
int read(int);
int occurs(int);
int after_pass(int);
int i,j,p,q,w,x,y,z,a[SIZE];
int main()
{
read(z);
sort(x);
occurs(w);
return 0;
}
int sort(int y)
{
for(i=0; i < SIZE; i++)
{
printf("After Pass %d: %d %d %d %d %d %d %d %d\n", i, a[0], a[1],
a[2], a[3], a[4], a[5], a[6], a[7]);
for(j=i+1;j < SIZE; ++j)
{
if(a[i] > a[j])
swap(&a[i],&a[j]);
}
}
}
int swap(int *c, int *d)
{
int tmp;
tmp = *c;
*c = *d;
*d = tmp;
}
int read(int z)
{
for(i=0; i < SIZE; i++)
{
printf("Enter value %d: \n", i);
scanf("%d", &a[i]);
}
}
int occurs (int w)
{
for(q=0; q < SIZE; q++)
{
for(p=q+1;p < SIZE; ++p)
{
if(a[q] < a[p])
swap(&a[q],&a[p]);
}
printf("%d occurs times.\n", a[q]);
}
}
Thank you in advance