首页 > 其他分享 >实现进制转化伪代码

实现进制转化伪代码

时间:2022-10-10 01:23:00浏览次数:45  
标签:进制 int 代码 转化 num newBase answer quo decimalNumber

用C语言实现下面伪代码描述的进制转换程序,提交运行结果截图,至少三张,包含转换为二进制,八进制,十六进制的截图

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int newBase,num;
int decimalNumber,quo,remainder,answer;
printf("Enter the number to be converted:");
scanf("%d\n",&decimalNumber);
printf("newBase:");
scanf("%d\n",&newBase);
quo=1;
num=1;
answer=0;
while(quo!=0)
{
quo=decimalNumber/newBase;
remainder=decimalNumber%newBase;
answer=answer+remainder*num;
num=num*10;
decimalNumber=quo;
}
printf("The answer is:%d",answer);
return 0;
}

 

 

 

 

 

标签:进制,int,代码,转化,num,newBase,answer,quo,decimalNumber
From: https://www.cnblogs.com/liudi20221408/p/16774043.html

相关文章