#include<stdio.h>
int getnumber(char *s,int *n)
{ char *p=s;
int k,m;
*n=0; m=1;
while ( *p != ')' ) p++;
k=atoi(p+1); p--;
if ( k==2 || k==10 )
{ while ( *p!='(' ) { (*n)+=((*p)-'0')*m; m*=k; p--; }
return k;
}
else return 0;
}
void exchange(char *s,int n,int k)
{ char str[80],str1[80];
int e,m,i;
e=( k==2 )?(10):(2); m=0;
while ( n )
{ str[m]=n%e+'0'; n/=e; m++;
}
for ( i=0;i<m;i++ ) str1[i]=str[m-i-1];
str1[i]=0;
sprintf(s,"(%s)%d",str1,e);
}
void main()
{ char str[256],str1[256];
int n,k;
scanf("%s",str);
k=getnumber(str,&n);
if ( k )
{ exchange(str1,n,k);
printf("%s ==> %s\n",str,str1);
}
}
#include <stdio.h>
int main()
{
int Type,a,b[10],i=0,c=0;
printf("请输入转换类型,1:十进制转二进制;2:二进制转十进制\n");
scanf("%d",&Type);
printf("请输入原数据\n");
scanf("%d",&a);
switch(Type)
{
case 1:
while(a!=0)
{
b[i]=a%2;
a/=2;
i++;
}
printf("二进制为:");
i--;
for(;i>=0;i--)
printf("%d",b[i]);
printf("\n");
break;
case 2:
while(a!=0)
{
b[i]=a%10;
a/=10;
i++;
}
i--;
for(;i>=0;i--)
c=c*2+b[i];
printf("十进制为:%d\n",c);
break;
}
}