我怎么做我的减的计算正确的答案? [关闭]

0

的问题

这一程序需要将用户输入的数字(最多10个),但用户一旦进入一个负整数程序的休息和进行计算的总和,差异、产品和商的所有数字输入。 我想我有一切权利,除了减的部分原因在于它始终显示了错误的答案。

#include <stdio.h>

int main() {
int i;
double number, sum = 0.0, difference = 0.0, product = 1, quotient = 1;

for (i = 1; i <= 10; ++i) {
  printf("Enter n%d: ", i);
  scanf("%lf", &number);

  // if the user enters a negative number, break the loop
  if (number < 0.0) {
     break;
  }

  sum += number; // sum = sum + number;
  difference -= number;
  product *= number;
  quotient = number / quotient;
}

 printf("Sum = %.2lf", sum);
 printf("\nDifference = %.2lf", difference);
 printf("\nProduct = %.2lf", product);
 printf("\nQuotient = %.2lf", quotient);

 return 0;
}

Here is an example of the code working with user input

c subtraction
2021-11-24 04:31:21
1

最好的答案

1

我不知道你的意思差别和我认为你应该注意的事实是,我们使用的差异进行比较时,只有2个数字。 如果你想知道什么你的计划是这样做是简单地增加负值的投入。 这就是为什么区别是负数的总和: 差= -(1)-(2)-(3)=-6

2021-11-24 06:37:36

哦. 我现在明白了为什么它要这么做。 谢谢你这么多! 所以它不可能减去多个号码?
s0mi

你是说某些东西喜欢的1-2+3=2-1+2至3=-2的? @s0mi
amirm

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................