Hashing using array and pointers

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> #include <stdlib.h> int hashIndex(int data,int size){ return data % size ; } int main(){ int size ,i,data; printf("Enter The Size of HashArray:"); scanf("%d",&size); int HashArray[size]; for(i = 0 ;i<size;i++){ printf("Enter the %d ele:",i+1); scanf("%d",&data); HashArray[hashIndex(data,size)] = data; } for(i = 0 ;i<size;i++){ printf("%d\n",HashArray[i]); } return 0; }
#include <stdio.h> #include <stdlib.h> int hashIndex(int data,int size){ return data % size ; } int main(){ int size ,i,data; printf("Enter The Size of HashArray:"); scanf("%d",&size); int *HashArray = (int *)malloc(sizeof(int)); int *temp = HashArray; for(i = 0 ;i<size;i++){ printf("Enter the %d ele:",i+1); scanf("%d",&data); HashArray[hashIndex(data,size)] = data; } for(i = 0 ;i<size;i++){ printf("%d\n",temp[i]); } return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines