Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
69689 李琥博 十进制小数转二进制 C++ Accepted 1 MS 272 KB 407 2024-04-06 12:15:04

Tests(10/10):


Code:

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