鱼C论坛

 找回密码
 立即注册
查看: 2348|回复: 11

[已解决]求和

[复制链接]
发表于 2024-5-22 21:23:11 | 显示全部楼层    本楼为最佳答案   
  1. sh-5.2$ cat main.cpp
  2. #include <iostream>
  3. #include <limits>
  4. #include <boost/multiprecision/cpp_dec_float.hpp>

  5. using std::cin, std::cout, std::endl;
  6. using std::numeric_limits;
  7. using std::setprecision;
  8. using boost::multiprecision::cpp_dec_float_100;

  9. int main() {
  10.     size_t count; cin >> count;
  11.     cpp_dec_float_100 result, temp;
  12.     for(size_t i = 0; i < count; ++i) {
  13.         cin >> temp; result += temp;
  14.     }
  15.     cout << setprecision(numeric_limits<cpp_dec_float_100>::max_digits10);
  16.     cout << result << endl;
  17.     return 0;
  18. }
  19. sh-5.2$ ./main
  20. 10
  21. 0.999999999
  22. 0.000000001
  23. -0.999999999
  24. -0.000000001
  25. 99999999.999999999
  26. 99999999.999999999
  27. 99999999.999999999
  28. 0.000000002
  29. -99999999.999999999
  30. 99999999.999999999
  31. 299999999.999999999
  32. sh-5.2$
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2024-5-23 21:10:04 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-29 09:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表