wyagl 2014-05-14 09:26 采纳率: 0%
浏览 2191

简易的10进制整数进制转换程序,要求支持2进制

#include
#include
int main()
{
int i,j;
int a[10];
int num;

scanf("%d",&num);

int b1=num;
for(i=0;b1!=0;i++)
{
    a[i]=b1%2;
    b1=b1/2;
}
for(j=i;j>=0;j--)
    {
        printf("%d",a[j]);
    }

return 0;
}

  • 写回答

1条回答

  • ORCHIACE 2014-05-14 12:49
    关注
    #include <stdio.h>
    
    typedef struct Consequence{
    int num;
    Consequence *next;
    
    };
    
    int main(){
    
    Consequence *first = new Consequence();
    Consequence *a = new Consequence();
    first->next = NULL;
    
    
    int m = 1000;
    int n = 16;
    
    while(m){
        Consequence *now = new Consequence();
        now->next  = first->next;
        first->next = now;
        now->num  = m%n;
        m = m/n;
    }
    
    a = first->next;
    while(a){
        if((a->num)<10 && (a->num)>=0)
            printf("%d",a->num);
        if((a->num)>=10 && (a->num)<16)
            printf("%c",(a->num)-10+'A');
        a = a->next;
    }
    
    return 0;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器