Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- In this problem you will compute lucky number based on person's name.
- If A=1, B=2, C=3 and so on Z=26.
- If we have a alphabet to digit conversion in this manner.
- You need to write a C program, to take full name as
- user input (preferably all in CAPS). Display substituted
- digit equivalent based on the numbers you assigned before,
- with spaces in between.
- Iteratively calculate sum of resultant digits. If the result > 9,
- calculate sum until you get a single lucky number.
- Optional: You can either accept input in all CAPS or
- Write logic such that you convert lower case characters to upper case.
- */
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- char name[1000],Num=0,temp=0,i,j,k,p,sum=0;
- gets(name);
- // scanf("%s",name);
- // name to number conversion
- for(p=0;name[p]!='\0';p++)
- {
- for(i=1,j=65,k=97;j<=90 ;i++,j++,k++) //check the string with ascii codes of alphabets
- {
- if(name[p] == j || name[p] == k)
- {
- Num= Num + i;
- }
- }
- }
- while(Num > 0)
- {
- while(Num != 0)
- {
- sum = sum+Num%10;
- Num=Num/10;
- }
- if(sum > 9)
- {
- Num = sum;
- sum = 0;
- }
- }
- printf("%d",sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement