2 wyagl wyagl 于 2014.05.14 17:26 提问

简易的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个回答

u014262884
u014262884   2014.05.14 20: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;
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!