Answer to Question #301663 in C for Kutty

Question #301663

An e‐commerce company is planning to start a new automated order I'd generator system fo book orders. For this purpose a random steing consisting of only digits is only fed to the system. From this random number, the order I'd is generated as a string which is a concatenation of sum of digits at extreme left and extreme right position, then the sum of digits at second left and second last right position and so on,until there is no digit left for consideration. Where there is a single digit then add zero to it .write an algorithm to find the order I'd for the book order

1
Expert's answer
2022-02-24T04:30:59-0500
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char sequence[100];
    char code[100];
    char ch[3];
    int digit, sumdig, len;    
    printf("Enter sequence of digits: ");
    scanf("%[^\n]", sequence);           
    len = strlen(sequence);    
    for(int i = 0; i < len / 2; i++)
    {                
        sumdig = 0;
        digit = sequence[i] - '0';
        sumdig += digit;
        digit = sequence[(len-1) - i] - '0';
        sumdig += digit;
        itoa(sumdig, ch, 10);
        strcat(code, ch);    
    }
    if (len % 2 != 0)
    {
        digit = sequence[(len / 2)] - '0';
        itoa(sumdig, ch, 10);
        strcat(code, ch);    
    }
    printf("\nCode: %s\n", code);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS