Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- float perimeter(float a, float b, float c)
- {
- if(a<=0||b<=0||c<=0)return -1;
- if(a+b<=c)return -1;
- if(a+c<=b)return -1;
- if(b+c<=a)return -1;
- return a+b+c;
- }
- float distance(int x1, int y1,int x2, int y2)
- {
- float w = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
- return w;
- }
- float area(float a, float b, float c)
- {
- if(a<=0||b<=0||c<=0)return -1;
- if(a+b<=c)return -1;
- if(a+c<=b)return -1;
- if(b+c<=a)return -1;
- float p;
- p = perimeter(a,b,c)/2;
- return sqrt(p*(p-a)*(p-b)*(p-c));
- }
- int main()
- {
- int points[3][2];
- char string[100];
- float distances[3];
- for(int i = 0;i<3;i++)
- {
- printf("Podaj wspolrzedne punktu: ");
- fgets(string, 100, stdin);
- int input = sscanf(string,"(%d, %d)",&points[i][0],&points[i][1]);
- if(input!=2)
- {
- printf("Incorrect input");
- return 1;
- }
- }
- distances[0] = distance(points[0][0],points[0][1],points[1][0],points[1][1]);
- distances[1] = distance(points[1][0],points[1][1],points[2][0],points[2][1]);
- distances[2] = distance(points[2][0],points[2][1],points[0][0],points[0][1]);
- //float x = perimeter(6.315819027092632, 7.698365764946384, 1.0800501719980466);
- //printf("%f, %.2fA dobra",x,area(distances[0],distances[1],distances[2]));
- if(area(distances[0],distances[1],distances[2])!=-1)
- printf("%.2f",area(distances[0],distances[1],distances[2]));
- else
- {
- printf("Incorrect input");
- return 1;
- }
- }
Add Comment
Please, Sign In to add comment