该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
这是网上十进制转八进制的代码,我稍微修改一下适合C语言。
#include
#include
void Decimal_to_Octal(char *octal_2,int decimal);
int main()
{
char octal_2[40];
Decimal_to_Octal(octal_2,12000);
printf("%s\n",octal_2);
system("pause");
return 0;
}
//十进制转八进制
void Decimal_to_Octal(char *octal_2,int decimal)
{
char octal[40];
int quotient = decimal; //商
int remainder = 0; //余数
int i,k;
for(i=0; i<40; i++)
{
remainder = quotient % 8;
switch(remainder)
{
case 0:
{
octal[i] = '0';
break;
}
case 1:
{
octal[i] = '1';
break;
}
case 2:
{
octal[i] = '2';
break;
}
case 3:
{
octal[i] = '3';
break;
}
case 4:
{
octal[i] = '4';
break;
}
case 5:
{
octal[i] = '5';
break;
}
case 6:
{
octal[i] = '6';
break;
}
case 7:
{
octal[i] = '7';
break;
}
default:
{
break;
}
}
quotient = quotient / 8;
if(0 == quotient)
{
octal[i+1] = 0;
break;
}
}
for(k=0; i>=0; i--,k++)
octal_2[k] = octal[i];
octal_2[k] = 0;
}