这就是任务
Input: 1 1
Output: 2
Input: -1 -1
Output: -2
Input: 1.1 2.2
Output: 3.3
我知道如何完成 3 项任务中的 2 项,但我不知道如何包含 float
当我有 int
时的数字数字。
最佳答案
您可以使用 %g
来获取您提到的预期输出。
#include <stdio.h>
int main()
{
float num1 = 0;
float num1 = 0;
float tot = 0;
printf("Enter number 1 = ");
scanf("%f", &num1);
printf("Enter number 2 = ");
scanf("%f", &num2);
tot = num1 + num2;
printf("Output = %g", tot);
return 0;
}
input : 2, 2
output :4
input : 5.5, 5
output: 10.5
关于c - 我不明白如何在简单计算器中输入或划分 float 和 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58373619/