本文共 4218 字,大约阅读时间需要 14 分钟。
c语言双精度的格式说明符
Format specifiers in C are used to accept and display data to the user. In programming terms, format specifiers help the compiler analyze the type of data being provided to the program.
C语言中的格式说明符用于接受数据并向用户显示数据。 用编程术语来说,格式说明符可帮助编译器分析提供给程序的数据类型。
Thus, it helps to find out the associated with the corresponding variable of the program.
因此,它有助于找出与程序的相应变量关联的 。
Points to Remember:
要记住的要点:
There are basically three elements that rule the format specifiers:
基本上有三个元素统治格式说明符:
Format Specifier | Description |
---|---|
%c | Accepts and prints characters |
%d | Accepts and prints signed integer |
%e or %E | Scientific notation of floats |
%f | Accepts and prints float numbers |
%hi | Prints the signed integer |
%hu | Prints unsigned integer |
%i | Accepts and prints integer values |
%l or %ld or %li | Long integer values |
%lf | Double values |
%Lf | Long double values |
%lu | Unsigned int or unsigned long |
%o | Provides the octal form of representation |
%s | Accepts and prints String values |
%u | Accepts and prints unsigned int |
%x or %X | Provides the hexadecimal form of representation |
%n | Provides a new line |
%% | This prints % character |
格式说明符 | 描述 |
---|---|
%C | 接受并打印字符 |
%d | 接受并打印带符号的整数 |
%e或%E | 浮点数的科学表示法 |
%F | 接受并打印浮点数 |
%hi | 打印有符号整数 |
%hu | 打印无符号整数 |
%一世 | 接受并打印整数值 |
%l或%ld或%li | 长整数值 |
%如果 | 双重值 |
%如果 | 长双精度值 |
%鲁 | Unsigned int或unsigned long |
%o | 提供八进制表示形式 |
%s | 接受并打印字符串值 |
%u | 接受并打印unsigned int |
%x或%X | 提供十六进制表示形式 |
%n | 提供新行 |
%% | 打印%字符 |
Integer format specifiers accept and print integer values through the program.
整数格式说明符通过程序接受并打印整数值。
Example:
例:
#includeint main() { int x = 0; printf("Enter the value of x:\n"); scanf("%d", &x); printf("%d\n", x); int z = 0; printf("Enter the value of z:\n"); scanf("%i", &z); printf("%i\n", z); return 0; }
Output:
输出:
Enter the value of x:1010Enter the value of z:2525
The “%d” format specifier takes the input number in a decimal format while the “%i” format specifier takes the input number into decimal or octal or hexadecimal format.
“%d”格式说明符将输入数字采用十进制格式,而“%i”格式说明符将输入数字采用十进制或八进制或十六进制格式。
Character format specifiers accept and print character values through the program.
字符格式说明符接受并通过程序打印字符值。
Example:
例:
#includeint main() { char x = ""; printf("Enter the character:\n"); scanf("%c", &x); printf("The entered character is:\n"); printf("%c\n", x); return 0; }
Output:
输出:
Enter the character:DThe entered character is:D
Octal format specifiers help provide an octal representation of the given integer.
八进制格式说明符有助于提供给定整数的八进制表示形式。
Example:
范例 :
#includeint main() { int num = 69; printf("The octal form of the input:\n"); printf("%o\n", num); return 0; }
Output:
输出:
The octal form of the input:105
Example:
例:
#includeint main(){ float num = 1.24578; printf("%f\n", num); printf("%0.2f\n", num); printf("%e\n", num); return 0;}
In the above piece of code, %0.2f provides the precision of up to two decimal values.
在上面的代码中,%0.2f提供了最多两个十进制值的精度。
Output:
输出:
1.2457801.251.245780e+00
Hexadecimal format specifiers provide the hexadecimal representation of the given integer.
十六进制格式说明符提供给定整数的十六进制表示形式。
Example:
例:
#includeint main(){ int num = 13; printf("%x\n", num); return 0;}
Output:
输出:
d
These format specifiers accept and print character arrays or strings through the program.
这些格式说明符通过程序接受并打印字符数组或字符串。
Example:
例:
#includeint main(){ char in_str[] = "Engineering Discipline"; printf("%s\n", in_str); return 0;}
Output:
输出:
Engineering Discipline
Thus, in this article, we have understood the role of format specifiers in the C language.
因此,在本文中,我们了解了C语言中格式说明符的作用。
翻译自:
c语言双精度的格式说明符
转载地址:http://fzlzd.baihongyu.com/