web123456

C++ Blue Bridge Cup basics commonly used to organize

5. Output format

There are three output formats that are normally used

        1.%md

It is possible to make int-types with less than m bits to rightaligned output, where the high digit is filled with a space and remains unchanged if itself exceeds m digits

  1. int a = 123;
  2. printf("%5d\n",a);
  3. // Output
  4. 123

        2.%0md

Unlike md, when the variable is less than m, it is preceded by enough zeros instead of spaces.

  1. int a = 123;
  2. printf("%5d\n",a);
  3. // Output
  4. 00123

        3.%.mf

It is possible to have floating point numbers retain m bits of output, taking the principle of rounding up to five into two

  1. double d1 = 12.3456;
  2. printf("%.3f,d1)
  3. // Output
  4. 12.346