You are using a version without Ads of this website. Please, consider donating:

### A little help :(

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657`` ``````#include #include #include using namespace std; int main() { double x,y,z,N; float Area,s; cin >> N; if (N > 1000) return 0; for (int i = 1; i <= N;i++) { cin >> x; if ( x > 5000) return 0; cin >> y; if ( y > 5000) return 0; cin >> z; if ( z > 5000) return 0; { s = ( x + y + z ) / 2; Area = sqrt ( s * ( s - x ) * ( s - y ) * ( s - z )); int B = Area; if ( (B % 3) == 0 && ( x != y != z)) { cout << x << " " << y << " " << z ; printf (" : RIGHT TRIANGLE WITH AREA %1.5f UNITS SQUARED\n",Area); } if ( Area == 0.00000) { cout << x << " " << y << " " << z ; cout << " : NOT A TRIANGLE" << endl; } else if ( (B % 3) > 0) { cout << x << " " << y << " " << z ; printf (" : TRIANGLE WITH AREA %1.5f UNITS SQUARED\n",Area); } } } return 0; }``````

I want the result like this

Sample Input
 3 3 5 4 1 2 1 3 3 1

Sample Output
 3 5 4 : RIGHT TRIANGLE WITH AREA 6.00000 UNITS SQUARED 1 2 1 : NOT A TRIANGLE 3 3 1 : TRIANGLE WITH AREA 1.47902 UNITS SQUARED

I'm not sure this is right?
`if ( (B % 3) == 0 && ( x != y != z))`

I think ` x != y != z` first evaluates `x != y`, to either true or false. Then it will compare either true or false with z. `true != z`, or `false != z`.

`true == not zero`, `false == zero`.

You might need to do this:

`if ( ((B % 3) == 0) && ( x != y && x != z && y != z))`

Also, `&&` has a higher precedence than `==`. So
`( (B % 3) == 0 && ( x != y != z))`, would first actually evaluate this to true or false: ` 0 && ( x != y != z)`. And it's going to be false no matter what because && needs both sides true to evaluate to true, and 0 is false. Then it would compare false with `(b % 3)`. So that whole statement is really equivalent to `if ((B % 3) == 0)`.
Last edited on
thank you sir for your quick response..

but the only thing that i want to change in my code is the position of the input and output

in here..the answer is correct..but it is not the way i want to do
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657`` ``````#include #include #include using namespace std; int main() { double x,y,z,N; float Area,s; cin >> N; if (N > 1000) return 0; for (int i = 1; i <= N;i++) { cin >> x; if ( x > 5000) return 0; cin >> y; if ( y > 5000) return 0; cin >> z; if ( z > 5000) return 0; { s = ( x + y + z ) / 2; Area = sqrt ( s * ( s - x ) * ( s - y ) * ( s - z )); int B = Area; if ( (B % 3) == 0 && ( x != y != z)) { cout << x << " " << y << " " << z ; printf (" : RIGHT TRIANGLE WITH AREA %1.5f UNITS SQUARED\n",Area); } if ( Area == 0.00000) { cout << x << " " << y << " " << z ; cout << " : NOT A TRIANGLE" << endl; } else if ( (B % 3) > 0) { cout << x << " " << y << " " << z ; printf (" : TRIANGLE WITH AREA %1.5f UNITS SQUARED\n",Area); } } } return 0; }``````

the result will become true..but everytime i input the value of x,y and z..it automatically compute..

i want to do like this:

1. I want to input the numbers like this
 3 <- this is the number of x,y & z i want to input 3 5 4 1 2 1 3 3 1

then..after that..i will output the result

 3 5 4 : RIGHT TRIANGLE WITH AREA 6.00000 UNITS SQUARED 1 2 1 : NOT A TRIANGLE 3 3 1 : TRIANGLE WITH AREA 1.47902 UNITS SQUARED

Problem Description
Given three positive integers x, y, and z, determine if the numbers correspond to the length of the sides of a triangle, and if it is, determine if the numbers correspond to the length of the sides of a right triangle. Furthermore, compute the area if the lengths are indeed lengths of the sides of a triangle

Input Format
The input starts with a positive integer N, followed by N triples of positive integers x, y, and z. The number N cannot exceed 1,000 while each of the numbers x, y, and z cannot exceed 5,000.

Output Format
For each test case, do the following:

(a) if the numbers correspond to the side lengths of a right triangle, output

x y z : RIGHT TRIANGLE WITH AREA ? UNITS SQUARED

(b) if the numbers correspond to the side lengths of a triangle (but not right triangle), output

x y z : TRIANGLE WITH AREA ? UNITS SQUARED

(c) otherwise output

x y z : NOT A TRIANGLE

The letters x, y, and z are the numbers inputted (in the original order) and the area ? is the computed area using Heron's formula. Heron's formula is discussed in this Wikipedia article.

Sample Input
3
3 5 4
1 2 1
3 3 1

Sample Output
3 5 4 : RIGHT TRIANGLE WITH AREA 6.00000 UNITS SQUARED
1 2 1 : NOT A TRIANGLE
3 3 1 : TRIANGLE WITH AREA 1.47902 UNITS SQUARED
 then..after that..i will output the result
To do that you will need to store all the input.
However, that is not what the problem is asking.

Your program is failing because your code is incorrect. Besides the `x != y != z` pointed by iseeplusplus
`Area = sqrt ( s * ( s - x ) * ( s - y ) * ( s - z ));` you may be computing the root of a negative number.

iseeplusplus wrote:
Also, `&&` has a higher precedence than `==`.
No, it does not.
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: