C语言程序十进制的数怎么转换成八进制的数?

2024-11-15 14:26:01
推荐回答(3个)
回答(1):

#include
#include
void main()
{
int n,a,sum = 0,i =0;
printf("十进制输出一个数n\n");
scanf("%d",&n);
while(n)
{
a = n%8;
n = n/8;
sum += a*pow(10,i);
i++;
}
printf("八进制输出sum:%d",sum);
}

回答(2):

#include

#include

void
main()
{
int
n,a,sum
=
0,i
=0;
printf("十进制输出一个数n\n");
scanf("%d",&n);
while(n)
{
a
=
n%8;
n
=
n/8;
sum
+=
a*pow(10,i);
i++;
}
printf("八进制输出sum:%d",sum);
}

回答(3):

C语言程序十进制的数转换成八进制的数的办法:
#include

#include

void
main()
{
int
n,a,sum
=
0,i
=0;
printf("十进制输出一个数n\n");
scanf("%d",&n);
while(n)
{
a
=
n%8;
n
=
n/8;
sum
+=
a*pow(10,i);
i++;
}
printf("八进制输出sum:%d",sum);
}