
2026年数字艺术字分层PSD素材适用于2026数字艺术字设计 本作品提供2026年数字艺术字分层PSD素材的图片会员免费下载,格式为PSD,文件大小为13.2M; 请使用软件Photoshop进行编辑,作品中文字及图均可以通过软件修改和编辑;
在本节中,我们将了解如何将数字(整数或浮点或任何其他数字类型数据)转换为字符串。
逻辑非常简单。这里我们将使用 sprintf() 函数。此函数用于将某些值或行打印到字符串中,但不在控制台中。这是 printf() 和 sprintf() 之间的唯一区别。这里第一个参数是字符串缓冲区。我们想要保存数据的地方。
Input: User will put some numeric value say 42.26 Output: This program will return the string equivalent result of that number like "42.26"
算法
Step 1: Take a number from the user Step 2: Create an empty string buffer to store result Step 3: Use sprintf() to convert number to string Step 4: End
示例代码
实时演示
#include<stdio.h>
main() {
char str[20]; //create an empty string to store number
float number;
printf("Enter a number: ");
scanf("%f", &number);
sprintf(str, "%f", number); //make the number into string using sprintf function
printf("</p><p>You have entered: %s", str);
}输出:
Enter a number: 46.3258 You have entered: 46.325802

















