C++ C+中的大值+;
我正在做一个斐波那契,我想把所有的数字都保存在一个.txt中,我已经完成了代码,但是当cicles得到大的值时,程序将其表示为指数,然后变大为.INF。 如何保存条目号C++ C+中的大值+;,c++,C++,我正在做一个斐波那契,我想把所有的数字都保存在一个.txt中,我已经完成了代码,但是当cicles得到大的值时,程序将其表示为指数,然后变大为.INF。 如何保存条目号 #include <iostream> #include <fstream> #include <string> using namespace std; int main() { ofstream File; File.open("fibo.txt"); d
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ofstream File;
File.open("fibo.txt");
double val0 = 0, val1 = 1, i = 0, n, out;
cout << "Enter n of Fibonacci(n): ";
cin >> n;
while (i < n) {
if (n == 0) {
File << i << "- " << 0 << endl;
i++;
}
else {
out = val0 + val1;
val0 = val1;
val1 = out;
i++;
File << i << "- " << val0 << endl;
}
}
File.close();
return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(){
流文件;
打开(“fibo.txt”);
双val0=0,val1=1,i=0,n,out;
cout>n;
而(i
#include <boost/multiprecision/cpp_int.hpp> // need this
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
using namespace boost::multiprecision;
int main()
{
ofstream File;
File.open("fibo.txt");
cpp_int val0 = 0, val1 = 1, out; // arbitrary precision integers
int i = 0, n;
cout << "Enter n of Fibonacci(n): ";
cin >> n;
while (i < n) {
if (n == 0) {
File << i << "- " << 0 << endl;
i++;
}
else {
out = val0 + val1;
val0 = val1;
val1 = out;
i++;
File << i << "- " << val0 << endl;
}
}
File.close();
return 0;
}
#包括//需要这个
#包括
#包括
#包括
使用名称空间std;
使用名称空间boost::multiprecision;
int main()
{
流文件;
打开(“fibo.txt”);
cpp_int val0=0,val1=1,out;//任意精度整数
int i=0,n;
cout>n;
而(i 对多精度库进行文件搜索。由于精度问题,请勿对此类问题使用浮点类型。double
仅为64位wide@AlexYan这与double
的大小没有多大关系,而是与它的精度有关。(而且double
的大小不能保证为64 BTW。)您可以在x64平台中使用unsigned long
(或size\u t
)而不是double
。在windows中,您还可以使用u int64。