第三十六次发博不知道有什么标题好
进制转换.....真的是了这么晚了嗨得像极了一个没有早训的人.....
#include<stdio.h> #include<stdlib.h> typedef struct node{ int data; struct node *next; }stack; stack * push(stack*ls,int x) { stack *p; if(ls==NULL)return 0; else{ p=(stack*)malloc(sizeof(stack)); p->data=x; p->next=ls; ls=p; return ls; } } void pop(stack *ls) { stack *p; if(ls==NULL) printf("error!"); while(p) { ls=p->next; printf("%d",p->data); free(p); p=ls; } } stack *transfer2(int x) { int i; stack *p; stack *ls=NULL; while(x){ i=x%2; p=(stack*)malloc(sizeof(stack)); p->data=i; p->next=ls; ls=p; x=x/2; } return ls; } stack *transfer8(int x) { int i,j; stack *p; stack *ls=NULL; while(x){ i=x%8; p=(stack*)malloc(sizeof(stack)); p->data=i; p->next=ls; ls=p; x=x/8; } return ls; } main() { int m; stack *ls; printf("请输入要转化的数:"); scanf("%d",&m); ls=transfer2(m); printf("对应的二进制数是:"); ls=transfer8(m); pop(ls); }