c & c++ output
发布日期:2021-05-07 01:48:07 浏览次数:16 分类:精选文章

本文共 458 字,大约阅读时间需要 1 分钟。

C++

#include 
#include
using namespace std;int main(){ cout << setprecision(3) << 3.1415926 << endl; // 控制输出数据的有效位数 cout << setiosflags(ios::fixed) << 3 << endl; // 以固定的浮点显示 cout << setiosflags(ios::fixed) << setprecision(2) << 3.1415926 << endl; // 保留n位小数输出 return 0;}

输出结果:

3.14

3
3.14

C

#include 
int main(){ printf("%.2f\n", 3.1415926); //3.14 printf("%.lf\n", 3.1415926); //3 return 0;}
上一篇:try to heap
下一篇:写一个计算两点间距离的函数

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2025年04月12日 12时04分52秒