Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
69685 何睿哲 十进制小数转二进制 C++ Accepted 1 MS 276 KB 410 2024-04-06 12:09:54

Tests(10/10):


Code:

#include<iostream> using namespace std; int main() { double n; cin>>n; int z=n,l[32]={},sum=0; double x=n-z; if(z==0) { cout<<0; } while(z) { l[sum++]=z%2; z/=2; } for(int i=sum-1; i>=0; i--) { cout<<l[i]; } if(x==0){ return 0; }else{ cout<<"."; } for(int i=0; i<9; i++) { x*=2; cout<<(int)x; x-=(int)x; if(x==0){ break; } } return 0; }