Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #define hash 11
- void fillhash(int n,int table[][20],int count[],int a[])
- {
- int i,j;
- for(i=0;i<n;i++)
- {
- j = a[i]%hash;
- table[j][count[j]] = a[i];
- count[j]++;
- }
- }
- int search(int table[hash][20],int count[],int ele)
- {
- int hk,i;
- hk = ele%hash;
- for(i=0;i<count[hk];i++)
- {
- if(ele==table[hk][i])
- return 1;
- }
- return 0;
- }
- void main()
- {
- int i,j,n,ele,count[hash]={0};
- int table[hash][20]={0},a[100];
- printf("\nEnter size of array\n");
- scanf_s("%d",&n);
- for(i=0;i<n;i++)
- {
- printf("\nenter %d element ",(i+1));
- scanf_s("%d",&a[i]);
- }
- printf("\n enter element to be searched");
- scanf_s("%d",&ele);
- fillhash(n,table,count,a);
- i=search(table,count,ele);
- if(i==1)
- printf("\n element found");
- else printf("\n elemnt not found");
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement