How to convert name to equivalent number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to convert name to equivalent number

for example input will be a name like input given is 'Sam' than output should be s+a+m=19+1+13=33

19th Jan 2017, 2:31 PM
shaikh saif
shaikh saif - avatar
1 Answer
+ 2
You just need to cast into int a char to get its ascii code. All letters ( lower and upper case don't be consecutive ) follows each others in the alphabetic order, so if you soustract the ( char code of 'a' - 1 ) to char code of a letter, you get his order number, starting from 1 for 'a'. You can proceed same way for upper case, with ( char code 'A' - 1 ) at calcul base... or convert all your string in upper or lower case...
19th Jan 2017, 5:41 PM
visph
visph - avatar