【发布时间】:2020-04-10 23:07:48
【问题描述】:
我想使用带有输入值的变量作为 C 中的小数位数。 我使用的 IDE 是 Windows 中的 CodeBlocks。 这是我尝试制作的代码示例(这是一个示例):
#include <stdio.h>
int main()
{
int value;
float number;
printf("Enter a number (float).\n");
scanf("%f", &number);
printf("Enter a value.\n");
scanf("%d", &value);
// here I'm trying to use the input value (float number) with the decimal places value (int value).
// In %.%df I'm trying to use the variable int value as the decimal places number
// (example: %.2f, being 2 the decimal places number) even though it is an int variable.
printf("The number %f with %d decimal places is %.%df.\n",
number, value, number, value);
return 0;
}
【问题讨论】:
-
你有什么问题?
标签: c