c++格式化输出数字

   
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{

    int a,b,c,d;
    cin>>a>>b;
    cin>>c>>d;
    int m,n;
    m=a+b;
    n=c*d;
    cout<<setw(4)<<setfill("0")<<m<<setw(4)<<setfill("0")<<n<<endl;//setw(N)代表几位数字,setfill("0")代表前边补零
    return 0;

}


输入:1 2 3 4

输出:   3  12



发布了7 篇原创文章 · 获赞 4 · 访问量 4095

猜你喜欢

转载自blog.csdn.net/mo926983/article/details/79837401