Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. /*
  2. In this problem you will compute lucky number based on person's name.
  3. If A=1, B=2, C=3 and so on Z=26.
  4. If we have a alphabet to digit conversion in this manner.
  5.  
  6. You need to write a C program, to take full name as
  7. user input (preferably all in CAPS). Display substituted
  8. digit equivalent based on the numbers you assigned before,
  9. with spaces in between.
  10.  
  11. Iteratively calculate sum of resultant digits. If the result > 9,
  12. calculate sum until you get a single lucky number.
  13.  
  14. Optional: You can either accept input in all CAPS or
  15. Write logic such that you convert lower case characters to upper case.
  16.  
  17. */
  18.  
  19. #include<stdio.h>
  20. #include<string.h>
  21. int main()
  22. {
  23. char name[1000],Num=0,temp=0,i,j,k,p,sum=0;
  24. gets(name);
  25. // scanf("%s",name);
  26. // name to number conversion
  27. for(p=0;name[p]!='\0';p++)
  28. {
  29. for(i=1,j=65,k=97;j<=90 ;i++,j++,k++) //check the string with ascii codes of alphabets
  30. {
  31. if(name[p] == j || name[p] == k)
  32. {
  33. Num= Num + i;
  34. }
  35. }
  36. }
  37. while(Num > 0)
  38. {
  39. while(Num != 0)
  40. {
  41. sum = sum+Num%10;
  42. Num=Num/10;
  43. }
  44. if(sum > 9)
  45. {
  46. Num = sum;
  47. sum = 0;
  48. }
  49. }
  50. printf("%d",sum);
  51.  
  52.  
  53.  
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement