#include <stdio.h>inta[ +];intk=0; void Change (int x,intR) { while(x) {a[k++]=x%r;x=x/R; }}intMain () {int x, R,i;printf("Enter a decimal number: \ n"); scanf"%d",&x);printf("Enter the decimal size you want to convert to: \ n"); scanf"%d", &r); Changex, R); for(i = k-1; I >=0; i--) {printf("%d", A[i]); }return 0;} /* #include<stdio.h>#include <string.h>void Tentoany (intNumber,char*str,intDigits) {intI=0;if(digits> -|| digits<2)//Non-2~ -In the system, it exits directly.return; while(number) {Switch (number%digits){//Handle case according to the remainder the: str[i++]=' F '; Break; Case -: str[i++]=' E '; Break; Case -: str[i++]=' D '; Break; Case A: str[i++]=' C '; Break; Case One: str[i++]=' B '; Break; CaseTen: str[i++]=' A '; Break; Default:str[i++]=number%digits+' 0 '; Break; } number=number/digits; } str[i]=' + '; Strrev (str);//strrevfunction definition in string.h, is the function of the reverse processing of the string,//The reason for reverse order here is because the result is the inverse of the binary}intMain () {intNumber,i;char str[ the];printf("Enter a decimal number:"); scanf"%d", &number);printf("\ n---------2 to 16 binary correspondence----------\ n"); for(i=2; i<= -; i++) {tentoany (number,str,i);printf("%d conversion to %d binary is:%s\ n", NUMBER,I,STR);}return 0;}*/
Decimal conversion to other binary (C language)