Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Find the decimal, octal and hexadecimal shapes corresponding to the input integer variable X and the output integer variable X of a C language program.
Find the decimal, octal and hexadecimal shapes corresponding to the input integer variable X and the output integer variable X of a C language program.
Printf has its own output format. %d is decimal output, %x is hexadecimal output, and %o is octal output. The output code "Feifei" of printf's own format has been given and will not be written any more. I'll give you a function transformation. You can have a look. # Including

void print(int i,char *s)

{

When (I-)

{

printf("%c ",s[I]);

}

printf(" \ n ");

}/* Decimal to Octal */

Void TentoE (integer)

{

int I = 0;

char str[ 10]; while(n & gt; 0)

{

str[I]= n % 8+' 0 ';

n/= 8;

i++;

}

Printf ("octal:");

print(i,str);

}/* Decimal to hexadecimal */

void TentoHex(int n)

{

int i=0,t;

char str[ 10];

while(n & gt; 0)

{

t = n % 16;

if(t & gt; = 10)

{

str[I]= t % 10+' a ';

}

other

str[I]= n % 16+' 0 ';

n/= 16;

i++;

}

printf(" Hex:");

print(i,str);

}

void main()

{

int x;

scanf("%d ",& ampx);

Printf ("algorithm: %d\n", x); //Decimal output.

TentoE(x); //Convert octal and output

TentoHex(x); //Convert hexadecimal and output.

}