点击(此处)折叠或打开
-
#include <stdio.h>
-
-
#define SHORT_MAX 0x7FFF
-
#define INT_MAX 0x7FFFFFFF
-
#define LONG_MAX 0x7FFFFFFFFFFFFFFF
-
-
void print_d()
-
{
-
int i = 10;
-
int j = -10;
-
-
printf("|%.5d|\n", i);
-
printf("|%05d|\n", i);
-
-
printf("|%.5d|\n", j);
-
printf("|%05d|\n", j);
-
-
printf("|%5d|\n", i);
-
printf("|%-5d|\n", i);
-
-
printf("|%+d|\n", i);
-
-
printf("|%*.*d|\n", 5, 3, i);
-
-
printf("%hd\n", SHORT_MAX);
-
printf("%d\n", INT_MAX);
-
printf("%ld\n", LONG_MAX);
-
-
printf("|% d|\n", i);
-
printf("|% d|\n", j);
-
-
printf("\n");
-
}
-
-
void print_s()
-
{
-
char* str = "abcde";
-
-
printf("|%5.3s|\n", str);
-
printf("|%-5.3s|\n", str);
-
-
printf("|%*.*s|\n", 5, 3, str);
-
-
printf("\n");
-
}
-
-
void print_f()
-
{
-
float f = 11.23456;
-
double df = 11.23456;
-
long double ldf = 99999999999998.4111111111;
-
-
printf("|%f|\n", f);
-
printf("|%f|\n", df);
-
-
printf("|%7.3f|\n", f);
-
printf("|%7.3f|\n", df);
-
printf("|%*.*f|\n", 7, 3, f);
-
printf("|%*.*f|\n", 7, 3, df);
-
-
printf("|%'Lf|\n", ldf);
-
printf("|%'.4Lf|\n", ldf);
-
-
printf("%e\n", df);
-
printf("%g\n", df);
-
-
printf("\n");
-
}
-
-
void print_o()
-
{
-
int i = 10000;
-
-
printf("%x\n", i);
-
printf("%o\n", i);
-
-
printf("%#x\n", i);
-
printf("%#o\n", i);
-
-
printf("\n");
-
}
-
-
int main(int argc, char *argv[])
-
{
-
print_d();
-
-
print_f();
-
-
print_s();
-
-
print_o();
-
-
return 0;
- }
|00010|
|00010|
|-00010|
|-0010|
| 10|
|10 |
|+10|
| 010|
32767
2147483647
9223372036854775807
| 10|
|-10|
|11.234560|
|11.234560|
| 11.235|
| 11.235|
| 11.235|
| 11.235|
|99999999999998.406250|
|99999999999998.4062|
1.123456e+01
11.2346
| abc|
|abc |
| abc|
2710
23420
0x2710
023420