Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C program to converting one digit from numeric to string . In the following C pr

ID: 3727011 • Letter: C

Question

C program to converting one digit from numeric to string . In the following C program there is a function calle digital_itob which takes two numeric arguments.The first number is the numeric digit value, up to the base.The second number is the base with which to give the representation.digit_itob has a return value is going to be a character, which is going to be the string representation of that digit value in that base. Let's say that we only output uppercase from this function.If the inputs are invalid, return ''.

Please fill the part saying insert the code

char digit_itob(int digit, int base) {
    /* insert your code here. */

    return '';
}

void main() {
    char digit;
    int number, base;

fprintf(stdout, "Test digit_itob. Format: <INTEGER_DIGIT> <BASE> ");
    fprintf(stdout, "> ");
    argcount = fscanf(stdin, "%d %d[ ]", &number, &base);

    if (argcount < 2) {
        fprintf(stdout, "Skipping Test digit_itob. Malformed Input.");
        fgets(buffer, MAX_LENGTH, stdin); /* Clearing */
    } else {
        fprintf(stdout, "Character Digit Result: ");
        fprintf(stdout, "%c ", digit_itob(number, base));
    }

Expected Outputs :
digit_itob( 15, 16) = 'F'

digit_itob( 0, 10) = '0'

digit_itob( 1, 16) = '1'

Explanation / Answer

char digit_itob(int digit, int base) {
if ( digit > base || digit < 0 || base < 0 ) return '';
if ( base < 11 ) {
return '0'+digit;
}
else {
if ( digit < 10 ) {
return '0'+digit;
}
else {
int tmp = digit%10;
return 'A'+tmp;
}
}
return '';
}