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

Complete the following code to perform the conversion from ASCII bit representat

ID: 3667689 • Letter: C

Question

Complete the following code to perform the conversion from ASCII bit representation for the variable n to the magnitude-only bit representation for the variable x. You may assume that

the user enters exactly three digits for the input. (Hint: what are the magnitude-only values for the bit patterns that represent the ASCII numeric symbols?)

#include <stdio.h>

main()

{

char n[4];

int x;

printf("Enter a 3-digit non-negative number: ");

scanf("%s", n);

...

...

...

printf("The number is %i ", x)

Explanation / Answer

#include <stdio.h>
main()
{
    char n[4];
    int x;
    int i;
    printf("Enter a 3-digit non-negative number: ");
    scanf("%s", n);
    x = 0;
    for (i=0; i<3; i++)
        x = 10*x + (n[i]-48);

    printf("The number is %i ", x);
}