{
  "question_id": 1057027,
  "question_title": "已知一个浮点数A（0<A<5），求它由哪两个整数B/C相除的值最接近",
  "question_content": "已知一个浮点数A（0<A<5），求它由哪两个整数B/C相除的值最接近，有相同值时要求B最小\n例如：\nA=0.2\nB=1 C=5",
  "difficulty": "中等",
  "answer_id": 1254068,
  "answer_content": "\n```\n#include <stdio.h>\n#include <math.h>\nint main () {\nfloat A = 0.2f;\nint x = 0;\nif (A < 0) { x = 1; A = 1/A; }\nfloat delta = 1;\nint B = 1, C = 1;\ndo\n{\nC = (int)(B * A);\ndelta = fabs(C/(float)B-A);\nB++;\n}\nwhile (delta > 0.000001); //如果你要高精度，就改小，否则改大\nif (x == 0)\nprintf(\"%d / %d\", C, B - 1);\nelse\nprintf(\"%d / %d\", B - 1, C);\nreturn 0;\n}\n\n```\n# 问题解决请点采纳",
  "tag_name": "c++",
  "cpp": "#include <stdio.h>\n#include <math.h>\nint main () {\n\tfloat A = 0.2f;\n\tint x = 0;\n\tif (A < 0) { x = 1; A = 1/A; }\n\tfloat delta = 1;\n\tint B = 1, C = 1;\n\tdo\n\t{\n\t\tC = (int)(B * A);\n\t\tdelta = fabs(C/(float)B-A);\n\t\tB++;\n\t}\n\twhile (delta > 0.000001); \n\tif (x == 0)\n\t\tprintf(\"%d / %d\", C, B - 1);\n\telse\n\t\tprintf(\"%d / %d\", B - 1, C);\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600469957",
  "status": 1,
  "keywords": "B树,算法高阶,高级数据结构,B树上的基本操作",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/99.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "linjun1735"
}