Notice: Undefined offset: 217149 in /var/www/html/qa-external/qa-external-users.php on line 744
forming triangle using the given values in c - OnlineGDB Q&A
Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

forming triangle using the given values in c

0 votes
asked Jun 26, 2018 by (240 points)
I want to check if the given valued are valid to form a triangle using c program. this is what I have written so far :

#include <stdio.h>

int main()

{

float a,b,c,f1,f2,f3;

printf("Input the three floating point values of the triangle: ");

scanf("%f%f%f",&a,&b,&c);

f1=a+b;

f2=b+c;

f3=c+a;

    if(f1<=c || f2<=a || f3<= b)

    {

    printf("the values are not valid to form a triangle");

}

else{

printf("the values are valid\n");

}

return 0;

}

Here should I use if(f1<=c && f2<=a && f3<= b)  instead of   if(f1<=c || f2<=a || f3<= b) ? if so why?

1 Answer

0 votes
answered Jun 27, 2018 by rodrigosul28 (180 points)
You have to confirm if all the numbers total is equal to 180ยบ, if so, this is a triangle, if not, it isn't. Simpler as that.

I've made an example for you:

#include <stdio.h>

int main() {
    float a,b,c,f1,f2,f3;
    
    printf("Input the three floating point values of the triangle: ");
    scanf("%f%f%f",&a,&b,&c);
    
    if (a + b + c == 180){
        printf("the values are valid\n");  
    } else {
        printf("the values are not valid to form a triangle");
    }
    return 0;
}

I used some parts of what u made.

Ur welcome :)

In this language, "&&" mean "And" and "||" mean "or".
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...