
C++中怎么输出一个很大的数?深圳
3个回答
展开全部
标准输出函数cout :
/*关于浮点数的格式*/
#include <iostream.h>
void main()
{
float f=2.0/3.0,f1=0.000000001,f2=-9.9;
cout<<f<<' '<<f1<<' '<<f2<<endl; //正常输出
cout.setf(ios::showpos); //强制在正数前加+号
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.unsetf(ios::showpos); //取消正数前加+号
cout.setf(ios::showpoint); //强制显示小数点后的无效0
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.unsetf(ios::showpoint); //取消显示小数点后的无效0
cout.setf(ios::scientific); //科学记数法
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.unsetf(ios::scientific); //取消科学记数法
cout.setf(ios::fixed); //按点输出显示
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.unsetf(ios::fixed); //取消按点输出显示
cout.precision(18); //精度为18,正常为6
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.precision(6); //精度恢复为6
}
操纵算子:
/*关于浮点数的格式*/
#include <iomanip.h>
void main()
{
float f=2.0/3.0,f1=0.000000001,f2=-9.9;
cout<<f<<' '<<f1<<' '<<f2<<endl; //正常输出
cout<<setiosflags(ios::showpos); //强制在正数前加+号
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<resetiosflags(ios::showpos); //取消正数前加+号
cout<<setiosflags(ios::showpoint); //强制显示小数点后的无效0
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<resetiosflags(ios::showpoint); //取消显示小数点后的无效0
cout<<setiosflags(ios::scientific); //科学记数法
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<resetiosflags(ios::scientific); //取消科学记数法
cout<<setiosflags(ios::fixed); //按点输出显示
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<resetiosflags(ios::fixed); //取消按点输出显示
cout<<setprecision(18); //精度为18,正常为6
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<setprecision(6); //精度恢复为6
}
■
/*关于浮点数的格式*/
#include <iostream.h>
void main()
{
float f=2.0/3.0,f1=0.000000001,f2=-9.9;
cout<<f<<' '<<f1<<' '<<f2<<endl; //正常输出
cout.setf(ios::showpos); //强制在正数前加+号
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.unsetf(ios::showpos); //取消正数前加+号
cout.setf(ios::showpoint); //强制显示小数点后的无效0
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.unsetf(ios::showpoint); //取消显示小数点后的无效0
cout.setf(ios::scientific); //科学记数法
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.unsetf(ios::scientific); //取消科学记数法
cout.setf(ios::fixed); //按点输出显示
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.unsetf(ios::fixed); //取消按点输出显示
cout.precision(18); //精度为18,正常为6
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout.precision(6); //精度恢复为6
}
操纵算子:
/*关于浮点数的格式*/
#include <iomanip.h>
void main()
{
float f=2.0/3.0,f1=0.000000001,f2=-9.9;
cout<<f<<' '<<f1<<' '<<f2<<endl; //正常输出
cout<<setiosflags(ios::showpos); //强制在正数前加+号
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<resetiosflags(ios::showpos); //取消正数前加+号
cout<<setiosflags(ios::showpoint); //强制显示小数点后的无效0
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<resetiosflags(ios::showpoint); //取消显示小数点后的无效0
cout<<setiosflags(ios::scientific); //科学记数法
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<resetiosflags(ios::scientific); //取消科学记数法
cout<<setiosflags(ios::fixed); //按点输出显示
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<resetiosflags(ios::fixed); //取消按点输出显示
cout<<setprecision(18); //精度为18,正常为6
cout<<f<<' '<<f1<<' '<<f2<<endl;
cout<<setprecision(6); //精度恢复为6
}
■
展开全部
这个数有多大?
如果超过了基本数据类型最大范围的话,需要用的高精度处理,也就是把一个数的每一位存到一个很大数组中的某一个元素里。大数的加减乘除算法在网上有很多思路,去搜搜看吧
如果超过了基本数据类型最大范围的话,需要用的高精度处理,也就是把一个数的每一位存到一个很大数组中的某一个元素里。大数的加减乘除算法在网上有很多思路,去搜搜看吧
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int 32位或64位
long 64位
double long 128位
显然楼主可以选择double long
long 64位
double long 128位
显然楼主可以选择double long
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询