十进制转二进制:
#include<stdio.h>
int main()
{int a[20],x;int rem,i=0;scanf("%d",&x);do{rem=x%2;x=x/2;a[i]=rem;i++;}while(x!=0);while(i>0)printf("%d",a[--i]);printf("\n");return 0;
}
十进制转八进制:
#include<stdio.h>
int main()
{int a[20],x;int rem,i=0;scanf("%d",&x);do{rem=x%8;x=x/8;a[i]=rem;i++;}while(x!=0);while(i>0)printf("%d",a[--i]);printf("\n");return 0;
}
十进制转十六进制
#include<stdio.h>
int main()
{char a[100];int x;int rem,i=0;scanf("%d",&x);do{rem=x%16;if(rem>9&& rem<16){a[i]=rem+'A'-10;}else if(rem>=0&&rem<=9){a[i]=(char)rem+'0';}x=x/16;i++;}while(x!=0);while(i>0)printf("%c",a[--i]);printf("\n");return 0;
}