Thursday, 8 September 2016

Hashing

Hashing
To count the frequency of the given number 
Example
Input:5
1
2
3
4
4
output:

1         1
2         1
3         1
4         2
explanation:
1 is present one time
2 is present one time
3 is present one time
4 is present two time

#include<stdio.h>
#include<string.h>
int main()
{
int hash[10000]={0},i,n,max=0;
int a[100];
printf("enter the no of number\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
   hash[a[i]]++;
   max=(max>a[i])?max:a[i];               // to find the maximum element because to run loop upto                                                                           //maximum element 
}
printf("count of the number \n");
for(i=0;i<=max;i++)
{
if(hash[i])
{
printf("%d \t %d\n",i,hash[i]);
}
}
return 0;
}



No comments:

Post a Comment

Troubleshooting in SQL

1. SSRS Error  Round () need to be done in  SQL itself  2. Default Date In SSRS  Start Date =CDate(Format(DateAdd("d",-50,Now()), ...