如何使用公式显示给定结果而不是使用if,else?

时间:2014-02-11 00:23:15

标签: c if-statement formula

我有一个作业提示,要求我给出这些结果:

Enter the three values to test (a b c): 3 4 5
a < b < c Status: 1
Pythagorean Triplet Status: 1

Enter the three values to test (a b c): 3 5 6
a < b < c Status: 1
Pythagorean Triplet Status: 0

Enter the three values to test (a b c): 4 3 5
a < b < c Status: 0
Pythagorean Triplet Status: 0

这就是我到目前为止所感到的失落:

#include<stdlib.h>
#include<math.h>
#define Status 1

int main()

{
  int a;
  int b;
  int c;
  int status;


  printf("Enter the three values to test (a b c):\n");
  scanf("%d%d%d\n", &a, &b, &c);
  printf("%d a < b < c Status: ",status);

  status =((((b-a)/2)+((b-a)/2))-((c-b)/2)+((c-b)/2))/2;

return(0);
}

我不能使用if,else语句。它需要适用于插入的任何三个值。我无法找出用于使其工作的正确公式。有关公式的任何建议吗?

2 个答案:

答案 0 :(得分:0)

类似* a + b * b == c * c?

答案 1 :(得分:0)

尝试:

status = !(a*a + b*b -c*c);