0

How can I write a code in C that checks if three values can represent the lenghts of a triangle?

I know I have to use the triangle inequality and i suppose I need to use the if-else statements for this. But I don't know how...

22nd Feb 2020, 8:19 AM
Elena Eremia
Elena Eremia - avatar
11 Respuestas
+ 3
On the other hand, I think you must check all situations: a + b > c a + c > b b + c > a This translates in your program as: if (((a+b) > c) && ((a+c) > b) && ((b+c) > a)) {....}
22nd Feb 2020, 9:11 AM
Mihai Apostol
Mihai Apostol - avatar
+ 2
Elena Eremia Your if condition is wrong. Here should be if((a + b) > c) { }
22nd Feb 2020, 8:54 AM
A͢J
A͢J - avatar
+ 2
you have to check for all 3 cases,meaning- a+b>c b+c>a a+c>b
23rd Feb 2020, 8:02 PM
Spandan Bhattacharya
Spandan Bhattacharya - avatar
+ 1
Yes! That' s what I wanted to ask ! Thank you!☺️
22nd Feb 2020, 9:21 AM
Elena Eremia
Elena Eremia - avatar
0
Have you tried? At least...
22nd Feb 2020, 8:21 AM
Mihai Apostol
Mihai Apostol - avatar
22nd Feb 2020, 8:37 AM
Elena Eremia
Elena Eremia - avatar
0
I cannot access that link, I guess only you can. Copy paste it here or in SL playground and link it here.
22nd Feb 2020, 8:40 AM
Mihai Apostol
Mihai Apostol - avatar
0
#include <stdio.h> int main() { printf("Checking if a, b and c can be the sides of a triangle\n"); int a, b, c; printf("a="); scanf("%i", &a); printf("b="); scanf("%i", &b); printf("c="); scanf("%i", &c); if("a+b>c ", &a,b,c ) { printf("a, b and c are forming a triangle");} else { printf("a, b and c are not forming a triangle");}
22nd Feb 2020, 8:51 AM
Elena Eremia
Elena Eremia - avatar
0
Oh! Yes! Thanks a lot!😁
22nd Feb 2020, 9:00 AM
Elena Eremia
Elena Eremia - avatar
- 1
Yes, I've tried but it doesn't work.
22nd Feb 2020, 8:26 AM
Elena Eremia
Elena Eremia - avatar
- 1
Post your try here, and we will try to help you.
22nd Feb 2020, 8:30 AM
Mihai Apostol
Mihai Apostol - avatar