⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 二进制数2.c

📁 精品专家讲述C语言附大量经典实例超值!!!!! ____________^-^___________^-^___________ 程序员必学
💻 C
字号:
/*另一种求二进制算法*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void main()
{
	float a,d,b=0;        /* d is a decimal,b is the change result,binary*/
	int i;
	printf("please input the decimal to change:\n");
	scanf("%f",&d);
	a=d;                /*d to a*/
	for(i=0;a>=1;i++)
	{
		if(pow(2,i)>a)
		{
			a=a-pow(2,i-1);
			b=b+pow(10,i-1);
			i=0;
		}
	}
	for(i=-1;a>0.000000001;i--)
	{
		if(pow(2,i)<=a)
		{
			a=a-pow(2,i);
			b=b+pow(10,i);
		}
	}
	printf("\n the changed result of %f is %f\n",d,b);
} 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -