/*lesson 3*/
#include <iostream>
#include <iomanip> //setw 域宽 函数使用
using namespace std;
int main()
{
//6550-655 数学表达式
int X=6550, Y =655;
cout << X << " - " << Y << " = " << (X-Y) << endl;
cout << setw(11) << X << endl;
cout << setw(5) << "-" << setw(6) << Y << endl;
cout << setw(11) << "---------" << endl;
cout << setw(11) << (X-Y) << endl;
system ("pause");
return 0;
}
运行结果:

该C++程序演示了简单的数学运算(6550减去655)并使用setw域宽函数进行格式化输出。程序首先计算差值,然后分别以不同宽度显示变量X、减号、变量Y以及结果。最后,程序暂停以展示输出结果。
122

被折叠的 条评论
为什么被折叠?



