当前位置:网站首页>[code hoof set novice village question 600] align left and right when outputting

[code hoof set novice village question 600] align left and right when outputting

2022-07-19 13:38:00 Sandm *

Topic link :



Code shoe set (matiji.net)

Their thinking :

Here we use %nd For example ,

  • The so-called left alignment , namely %-nd,

That is, multiple lines of different The numbers are aligned to the left at the same time , The number alignment between lines is realized by spaces

  • Right alignment , namely %nd

That is, multiple lines of different numbers are aligned based on the rightmost

Be careful :

Among them %nd And %m.nf

The width and precision in must be constant , It can't be a variable

Reference code :

#include<bits/stdc++.h> 

using namespace std;

int main( )
{
    double a = 3.141593,b = 22.345600;

    printf("%-14lf %14lf\n",a,a);// Don't forget it's  %lf  No  %d
    printf("%-14lf %14lf",b,b);

    return 0;
}

原网站

版权声明
本文为[Sandm *]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207171822461120.html