patryk178

Dante 7.14

Jan 20th, 2021 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. float perimeter(float a, float b, float c)
  6. {
  7.     if(a<=0||b<=0||c<=0)return -1;
  8.     if(a+b<=c)return -1;
  9.     if(a+c<=b)return -1;
  10.     if(b+c<=a)return -1;
  11.     return a+b+c;
  12. }
  13.  
  14. float distance(int x1, int y1,int x2, int y2)
  15. {
  16.     float w = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
  17.     return w;
  18. }
  19.  
  20. float area(float a, float b, float c)
  21. {
  22.     if(a<=0||b<=0||c<=0)return -1;
  23.     if(a+b<=c)return -1;
  24.     if(a+c<=b)return -1;
  25.     if(b+c<=a)return -1;
  26.     float p;
  27.     p = perimeter(a,b,c)/2;
  28.     return sqrt(p*(p-a)*(p-b)*(p-c));
  29.  
  30. }
  31.  
  32. int main()
  33. {
  34.     int points[3][2];
  35.     char string[100];
  36.     float distances[3];
  37.     for(int i = 0;i<3;i++)
  38.     {
  39.         printf("Podaj wspolrzedne punktu: ");
  40.         fgets(string, 100, stdin);
  41.         int input = sscanf(string,"(%d, %d)",&points[i][0],&points[i][1]);
  42.         if(input!=2)
  43.         {
  44.             printf("Incorrect input");
  45.             return 1;
  46.         }
  47.     }
  48.  
  49.     distances[0] = distance(points[0][0],points[0][1],points[1][0],points[1][1]);
  50.     distances[1] = distance(points[1][0],points[1][1],points[2][0],points[2][1]);
  51.     distances[2] = distance(points[2][0],points[2][1],points[0][0],points[0][1]);
  52.  
  53.     //float x = perimeter(6.315819027092632, 7.698365764946384, 1.0800501719980466);
  54.     //printf("%f, %.2fA dobra",x,area(distances[0],distances[1],distances[2]));
  55.     if(area(distances[0],distances[1],distances[2])!=-1)
  56.         printf("%.2f",area(distances[0],distances[1],distances[2]));
  57.     else
  58.     {
  59.         printf("Incorrect input");
  60.         return 1;
  61.     }
  62.  
  63. }
  64.  
Add Comment
Please, Sign In to add comment