欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C语言 输出二进制数

程序员文章站 2022-03-01 13:33:38
...
#include<stdio.h>
int Binary_number(int dec){
	int result = 0,temp = 1,yushu = 0;
	while(1){
		yushu = dec%2;
		dec/=2;
		result+=yushu*temp;
		temp*=10;
		if(dec<2)
		{
			result+=dec*temp;
			break;
		}
	}
	
	return result;
	
}
int main(){
	int num;
	printf("Please input the number: ");
	scanf("%d",&num);
	printf("The Binary number is: %d\n",Binary_number(num));
	return 0;
}
相关标签: c