十进制转换为八进制
#include <stdio.h>
#include <math.h>
int convertDecimalToOctal(int n);
int main()
{
int n;
printf("输入一个十进制数: ");
scanf("%d", &n);
printf("十进制数 %d 转换为八进制位 %lld", n,convertDecimalToOctal( n) );
return 0;
}
int convertDecimalToOctal(int n)
{
int octalNumber= 0;
int i = 1;
while (n!=0)
{
octalNumber+=(n%8)*i;
n/=8;
i *= 10;
}
return octalNumber;
}
标签:转换,int,octalNumber,convertDecimalToOctal,八进制,十进制
From: https://www.cnblogs.com/yesiming/p/17461627.html