- Question requirements : The octal and hexadecimal numbers corresponding to the decimal integer 1234 will be output.
Enter description :
without
Output description :
Octal and hexadecimal (uppercase letters) corresponding to decimal number 1234, separated by spaces, and required to display a leading 0 before the octal number and a leading 0X before the hexadecimal number
#include<stdio.h>
int main()
{
printf("%#o,%#X\n", 1234,1234);//直接在printf中进行格式控制
return 0;
}
Result output:
Code description :
1. Format output
Here, format control is performed directly in printf. If you want to output octal, use %o, and to output hexadecimal, use %X.
Common output formats are:
%d: output integer (usually used to output int type integer)
%f: output a single-precision floating-point number (float type)
%lf: output double-precision floating-point number (double type)
%c: output character
%s: output string
%p: output address format
(For more information, please refer to the website: scanf, fscanf, sscanf, scanf_s, fscanf_s, sscanf_s - cppreference.com )
2. Uppercase and lowercase letters
The title requires the letters in the output hexadecimal to be capitalized, then the X in the output format (%X) should be capitalized. If X is lowercase, the output D will become d.
3. Pilot display
To display the leader, we can add # directly after %