Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- typedef struct point2D {
- double x;
- double y;
- }
- point2D;
- float distance (point2D t1, point2D t2) {
- return sqrt((t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y));
- }
- typedef struct point3D {
- double x;
- double y;
- double z;
- }
- point3D;
- float distance3D(point3D t1, point3D t2) {
- return sqrt((t1.x-t2.x)*(t1.x-t2.x)+(t1.y-t2.y)*(t1.y-t2.y)+(t1.z-t2.z)*(t1.z-t2.z));
- }
- int collinear(point2D t1,point2D t2, point2D t3) {
- if((t2.y-t1.y)/(t2.x-t1.x)==(t3.y-t2.y)/(t3.x-t2.x))
- return 1;
- else
- return 0;
- }
- int main() {
- float x1, y1, x2, y2;
- scanf("%f %f", &x1, &y1);
- scanf("%f %f", &x2, &y2);
- point2D t1 = { x1, y1 };
- point2D t2 = { x2, y2 };
- printf("%.2f\n", distance(t1, t2));
- float z1, z2;
- scanf("%f %f", &z1, &z2);
- point3D t3 = {x1, y1, z1};
- point3D t4 = {x2, y2, z2};
- printf("%.2f\n", distance3D(t3, t4));
- point2D t5 = {z1, z2};
- printf("%d\n", collinear(t1, t2, t5));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement