Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
69672 许铭锐 十进制小数转二进制 C++ Accepted 1 MS 272 KB 426 2024-04-06 11:59:01

Tests(10/10):


Code:

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