Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C language programming: take X as a decimal integer, and program to convert X into the corresponding octal number for output.
C language programming: take X as a decimal integer, and program to convert X into the corresponding octal number for output.
The first thing to know is how to convert.

Divide decimal to octal by 8 to get the remainder.

For example, 562 1 is converted to octal.

8|562 1

702-5 First place (unit)

87-6 second place

10-7 third place

1-2 fourth place

The final octal number: 127658.

The following is written according to the above rules:

# contains "stdio.h"

void main()

{

int a,b,c,d,i=0,j,num = 0;

Printf ("Please enter a decimal number: \ t");

scanf("%d ",& ampa); //Assignment is the number you enter.

b = a % 8; //Ask for the number of people.

And (! (a/8== 1)) // Stop the loop when A is divisible by 8.

{

i++; //every cycle I plus 1.

a = a/8; //Divide by 8 and get the quotient at one time.

c = a % 8; //Modulus, both of which are residues.

for(j = 0; J< me; J++) // Calculate the number of digits entered.

{

d = c * 10; //Multiply by 10 once every period.

}

mun = mun+d;

}

mun = mun+b;

Printf ("Decimal to octal number is %d", mun);

}

Not necessarily right, this is the general idea, you may have to debug yourself if you have any problems!

I just learned C language, too. My QQ is QQ86573984. If you have any questions, let's discuss them together.