请问我的这个程序哪里出问题了,我感觉是数组string,但不知道怎么改?
#include <stdio.h>void dec_to_bin(char s[],int num){
int a[100],m,i=0,j,k;
while(1){
m=num%2;
a[i]=m;
num=num/2;
if(num==0)break;
i++;
}
k=i;j=0;
for(;j<=k;j++,i--){
s[j]=a[i];
}
}
int bin_to_dec(const char s[]){
int i = 0, n = 0;
while(s[i]!='\0'&&(s[i]=='0'||s[i]=='1')){
n = n * 2 + (s[i] - '0');
++i;
}
return n;
}
main(){
char string[100]={'\0'};
int in_num,out_num;
printf("输入一个十进制数:");
scanf("%d",&in_num);
dec_to_bin(string,in_num);
printf("二进制是:%s\n",string);
out_num=bin_to_dec(string);
printf("十进制是:%d\n",out_num);
}