-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program (13)Hasing Mid Squre.c
71 lines (62 loc) · 1.22 KB
/
Program (13)Hasing Mid Squre.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
#include<stdlib.h>
#define MAX 100
int htable[MAX];
void init()
{
int i;
for(i=0; i<100; i++)
htable[i]=-1;
}
void insert()
{ int key,ind,sq;
printf("Enter value to insert\n");
scanf("%d",&key);
sq=key*key;
ind=sq%1000;
ind=ind/10;
htable[ind]=key;
printf("Value inserted Successfully\n");
}
void search()
{ int key,sq,ind;
printf("Enter value to search\n");
scanf("%d",&key);
sq=key*key;
ind=sq%1000;
ind=ind/10;
if(htable[ind]==key)
printf("\nValue %d found at location %d\n",key,ind);
else
printf("\nValue %d not found...\n",key);
}
void display()
{int i;
for( i=0; i<MAX; i++)
{
if(htable[i]!=-1 )
printf("%d ",htable[i]);
}
}
int main()
{ int ch,status;
init();
while(1)
{
printf("\n1.Insert data\n2.Search\n3.Display\n4.Exit\n");
printf("Enter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:insert();
break;
case 2: search();
break;
case 3: display();
break;
case 4: exit(0);
default : printf("\nWrong choice\n");
}
}
return 0;
}