C语言 输出二进制数

#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
",Binary_number(num));
	return 0;
}
原文地址:https://www.cnblogs.com/HBU-xuhaiyang/p/12520636.html