Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Write a program in C++ language to convert a long integer with radix 10 into an integer with radix 8 and radix 16. It's best to write it in a file.
Write a program in C++ language to convert a long integer with radix 10 into an integer with radix 8 and radix 16. It's best to write it in a file.
# including "iostream"

Use namespace std

int main()

{ long m,k,w,q,p,a,b[ 1000],y,I; //Visual editor Tc can use long integer or unsigned long integer.

char c[39]= { " 0 123456789 abcdefghijklmnopqrstuvwxyz " };

Cout & lt& lt "Please enter the number to be converted"

CIN & gt; & gtq;

p = q;

y = 0;

w = 8;

while(q)

{ b[y++]= q % w;

q/= w;

}

Cout < < "octal is:";

for(I = y- 1; I & gt=0; I-)

cout & lt& ltc[b[I]];

cout & lt& ltendl

w = 16; //w changes can be converted to binary 36.

q = p;

y = 0;

while(q)

{ b[y++]= q % w;

q/= w;

}

The cardinality of cout & lt< "16 is:";

for(I = y- 1; I & gt=0; I-)

cout & lt& ltc[b[I]];

cout & lt& ltendl

getchar(); getchar(); getchar(); getchar();

Returns 0;

}