Friday 20 July 2018

Alphabets Plus Digits Sum

The program must accept a string S which has alphabets and digits as the input. The program must find the sum of all digits as D in the input string S. Then the program must print the alphabets which are D positions away from the alphabets in the string S.

Example

Input
435acl

The digits are 4,3,5 and their sum D=12

Output
mox
The alphabets in the input are a, c, l
a+12 = m    c+12 = o    l+12 = x

Program
#include <stdio.h>
#include <ctype.h>

int main()
{
    int D=0,i,c=0;
    char S[100];
    scanf("%s",S);
    for(i=0;S[i]!='\0';i++)
        if (isdigit(S[i]))
        {
            D+=S[i]-48;
        }
    D=D%26;

    for(i=0;S[i]!='\0';i++)
   {
      
        if (isalpha(S[i])) 
       {
           
            S[i]=tolower(S[i]);
            c=D+S[i];
            
            if(c>122)
            {
                c=96+(c-122);
            }
              
            printf("%c",c);
        }
    }   
}

OUTPUT


1121ZU                                                                                                                         
                                                                                                                              
ez