Advertisement
18126

Day1(ex4)

Jul 7th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.     float a, b, c;
  8.     printf("Enter side a: ");
  9.     scanf("%f", &a);
  10.     printf("Enter side b: ");
  11.     scanf("%f", &b);
  12.     printf("Enter side c: ");
  13.     scanf("%f", &c);
  14.     if(a <= 0 || b <= 0 || c <= 0) {
  15.         printf("Not a valid triangle, sides can't be negative.");
  16.         return 0;
  17.     }
  18.     float small1 = a, small2 = a, big = a;
  19.     for(int i = 0; i < 2; i++) {
  20.         if(i == 0) {
  21.             if(b < small1) {
  22.                 small1 = b;
  23.             }
  24.             if(b > big) {
  25.                 big = b;
  26.             }
  27.         }
  28.         else if(i == 1) {
  29.             if(c < small1) {
  30.                 small1 = c;
  31.                 small2 = b;
  32.             }
  33.             else if(c < small2) {
  34.                 if(c < small1) {
  35.                     small1 = c;
  36.                     small2 = b;
  37.                 }
  38.                 else {
  39.                     small2 = c;
  40.                 }
  41.             }
  42.             else if(c > big) {
  43.                 big = c;
  44.             }
  45.         }
  46.     }
  47.     if(small1 + small2 < big) {
  48.         printf("Not a valid triangle, the 2 smallest sides combined are less than the big one.");
  49.         return 0;
  50.     }
  51.     //P and S
  52.     printf("P = %.2f\n", (a+b+c));
  53.     float p = (a+b+c)/2;
  54.     printf("S = %.2f\n", (sqrt(p*(p-a)*(p-b)*(p-c))));
  55.     //Type
  56.     if(a == b == c) {
  57.         printf("The triangle is equilateral.\n");
  58.     }
  59.     else if(a == b || b == c || c == a) {
  60.         printf("The triangle is isosceles.\n");
  61.     }
  62.     else {
  63.         printf("The triangle is scalene.\n");
  64.     }
  65.     //Type(angles)
  66.     if(pow(a, 2)+pow(b, 2)<pow(c, 2)) {
  67.         printf("The triangle is obtuse.\n");
  68.     }
  69.     else if(pow(a, 2)+pow(b, 2)==pow(c, 2)) {
  70.         printf("The triangle is right.\n");
  71.     }
  72.     else {
  73.         printf("The triangle is acute.\n");
  74.     }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement