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...
11 ответов
+ 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)) {....}
+ 2
Elena Eremia Your if condition is wrong. Here should be
if((a + b) > c) {
}
+ 2
you have to check for all 3 cases,meaning-
a+b>c
b+c>a
a+c>b
+ 1
Yes! That' s what I wanted to ask ! Thank you!☺️
0
Have you tried? At least...
0
Here is what I've tried: https://www.onlinegdb.com/edit/rku_wwAm8
0
I cannot access that link, I guess only you can.
Copy paste it here or in SL playground and link it here.
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");}
0
Oh! Yes! Thanks a lot!😁
- 1
Yes, I've tried but it doesn't work.
- 1
Post your try here, and we will try to help you.