Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
99940 | 任斌 | 十进制小数转二进制 | C++ | Accepted | 1 MS | 272 KB | 357 | 2024-12-01 11:18:23 |
#include<bits/stdc++.h> using namespace std; int main() { double n,b; cin>>n; int a=n; int x[33]; int i=0; b=n-a; if(a==0)cout<<0; while(a!=0){ x[i]=a%2; a/=2; i++; } for(int j=i-1;j>=0;j--){ cout<<x[j]; } if(b!=0){ cout<<"."; while(b!=0){ b*=2; cout<<(int)b; b-=(int)b; } } return 0; }