1.3 编写一个输出任意double类型的数值(可以使负数,只能用I/O的printDigit)
#include <iostream> using namespace std; void printInt(int a) { if(a >= 10) printInt(a / 10); cout<<(a%10); } void printReal(double a) { while(!(a > -0.0000001 && a < 0.000001)) { a *= 10; cout<<(int)a; a = a - int(a); } } void test(double a) { if(a < 0.0) { cout<<"-"; a = -a; } printInt((int)a); cout<<"."; printReal( a - int(a)); } int main() { // your code goes here test(-123.45); return 0; }
时间: 2024-10-10 05:04:06