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\n",Binary_number(num));
	return 0;
}
全部评论

相关推荐

肖先生~:大一点得到公司面试更能学到点东西
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务