Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
108219 彭林江 十进制小数转二进制 C++ Accepted 1 MS 268 KB 544 2025-01-19 15:38:02

Tests(10/10):


Code:

#include<bits/stdc++.h> using namespace std; int y[100]; int cnt = 0; int main(){ double n; cin >> n; int z = n; // 将n的整数装入z double x = n-z; // 算出小数 if(z == 0){ cout << 0; } while(z != 0){ int yu = z % 2; y[cnt] = yu; cnt++; z = z/2; } for(int i = cnt-1; i>=0; i--){ cout << y[i]; } if(x > 0){ cout << "."; }else{ return 0; } for(int i = 0; i < 9; i++){ x = x * 2; int zz = x; cout << zz; x = x-zz; if(x == 0){ return 0; } } return 0; }