Hash an integer to a position where the key is the mod 10 of that number.
# Program to hash an integer to a position where the key is the mod 10 of that number
h=Hash.new #creating an emty hash
print("Enter an integer that you want to hash and store:")
str=gets #The no. entered through the keyboard is stored in str as a string
str.chomp! #To remove the trailing newline
num=str.to_i #The string str is converted into an int
key=num%10 #The key is obtained by performing the modulus of the given no.
h.store(key,num) #The no. is stored in the hash at key
#h[:key]=num
print("The value stored is #{h[key]}\n The location where it is stored is #{key}\n")
#To display the hash
print("Displaying the hash\n")
print("key=>value: #{h.inspect}\n")