Quick actions

cmd+k|ctrl+k

Navigation

Languages

U79d

Snippet info

Language

C

Visibility

public

Author

sriram

Created

2023-08-16T05:43:02.652674Z

Updated

2023-08-16T05:43:02.652674Z

#include<stdio.h>
#include<string.h>
#include <math.h>
#define MAX 10
#define A 0.6180339887
int h(int k, int m)
{
return floor(m * (k*A - floor(k*A)));
}
struct telephonebook
{
 char name[MAX];
 long int phoneno;
 
};
int main()
{
 struct telephonebook arr_client[MAX];
 int recordCount=0;
 int arrayIndex=0;
 int i;
 int key;
 long int key_phoneno=0
int flag = 1;
 while(flag == 1)
 {
 printf("Enter Client Phone Number: ");
 scanf("%ld", &key_phoneno);
 //hash calculation using multiplication method
 arrayIndex = h(key_phoneno,10);
 printf("HASH VALUE=%d\n",arrayIndex);
 // using hash value to store a student record
 printf("Enter Client name: ");
 scanf("%s", arr_client[arrayIndex].name);
 arr_client[arrayIndex].phoneno = key_phoneno;
 recordCount++;
 printf("Do you want to add more entry:(Yes-> 1/No->0)");
 scanf("%d",&flag);
 }
 printf("\n");
 // searching a student information based on hash value
 printf("Enter hash value to show the details:");
 scanf("%d", &arrayIndex);
 printf("%s \t %ld \t",arr_client[arrayIndex].name, arr_client[arrayIndex].phoneno); 
 return 0;
}
 
INFO