What I try to do is count the frequency of input number but now my problem is it will print an already printed element.
Ex.
Input: 1 3 5 2 3 1
It will output:
1 2
3 2
5 1
2 1
3 2
1 2
Expect ouput:
1 2
3 2
5 1
How do I fix this any suggestion?
#include<stdio.h>
int n = 0;
int number[100] = {0};
int frequency[100] = {0};
int count = 0;
int i = 0, j = 0, k = 0;
int main()
{
scanf("%d",&n);
for(count=0; count<n; count++)
{
scanf("%d",&number[count]);
}
///////////////////////////////////////////////
for(i = 0; i<n; i++)
{
for(j = 0; j<n; j++)
{
if(number[i] == number[j])
{
frequency[k] = frequency[k]+1;
}
}
k = k+1;
}
////////////////////////////////////////////////
for(k=0, i=0; k<n; i++, k++)
{
printf("%d %d\n",number[i],frequency[k]);
}
}