Decimal conversion to other binary (C language)

Source: Internet
Author: User

#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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.