Type of Triangle


/ Published in: C
Save to your folder(s)

Given a, b, c find which kind of triangle can be build with those values.


Copy this code and paste it in your HTML
  1. #include<stdio.h>
  2. #define NONE -1
  3. #define EQUILATERAL 0
  4. #define ISOSCELES 1
  5. #define SCALENE 3
  6.  
  7. int isTriangle(int a, int b, int c)
  8. {
  9. if(a < 1 || b < 1 || c < 1)
  10. return NONE;
  11. if(a+b <= c || a+c <= b || c+b <= a)
  12. return NONE;
  13. if(a == b && a == c)
  14. return EQUILATERAL;
  15. if(a == b || b == c || a == c)
  16. return ISOSCELES;
  17. else
  18. return SCALENE;
  19. }
  20.  
  21. int main()
  22. {
  23. printf("%d\n", isTriangle(11,10,17));
  24. printf("%d\n", isTriangle(11,10,11));
  25. printf("%d\n", isTriangle(11,11,11));
  26. printf("%d\n", isTriangle(11,110,11));
  27. printf("%d\n", isTriangle(11,0,11));
  28. return 0;
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.