Answer to Question #302640 in C for Swapna

Question #302640

A college has to generate the roll number of the students for the internal examination. The college admin authority has to generate the roll numbers from the registration number of the students. Every student has a registration number. The registration number is a numeric number. The authority has devised a method for generating the roll numbers from the registration number. To generate the roll number, the pairs of adjacent digits are formed from the start of the roll number. From each pair the lexicographically smallest digit will be removed. If a digit will be left unpaired then that digit will be taken as it is in the roll number.





Write an algorithm for implementing





the devised method for the college





system to find the roll number from





the registration number,

1
Expert's answer
2022-02-25T07:52:54-0500
#include <stdlib.h>

int main()
{
    char regnumber[100];
    char rolnumber[100];
    char ch[5];
    int digit1, digit2, len;    
    printf("Enter registration number: ");
    scanf("%[^\n]", regnumber);            
    len = strlen(regnumber);    
    for(int i = 0; i < len - 1; i+=2)
    {                
        digit1 = regnumber[i] - '0';
        digit2 = regnumber[i + 1] - '0';
        if (digit1 > digit2)
            itoa(digit1, ch, 10);
        else itoa(digit2, ch, 10);
        strcat(rolnumber, ch);    
    }
    if (len % 2 != 0)
    {
        digit1 = regnumber[len - 1] - '0';
        itoa(digit1, ch, 10);
        strcat(rolnumber, ch);    
    }
    printf("\nRoll number is: %s\n", rolnumber);
}

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