Skip to content

Instantly share code, notes, and snippets.

@Kinjalrk2k
Last active August 19, 2018 10:51
Show Gist options
  • Save Kinjalrk2k/80e71c31ff7aa56a2da0c23a0f48953e to your computer and use it in GitHub Desktop.
Save Kinjalrk2k/80e71c31ff7aa56a2da0c23a0f48953e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
struct point
{
double x, y, z;
};
int main()
{
//double x1, y1, z1;
//double x2, y2, z2;
struct point p1, p2;
double dist;
printf("Enter the values of x, y and z for Point 1:\n");
//scanf("%lf%lf%lf", &x1, &y1, &z1);
scanf("%lf%lf%lf", &p1.x, &p1.y, &p1.z);
printf("Enter the values of x, y and z for Point 2:\n");
//scanf("%lf%lf%lf", &x2, &y2, &z2);
scanf("%lf%lf%lf", &p2.x, &p2.y, &p2.z);
//dist=sqrt(pow((x2-x1), 2) + pow((y2-y1), 2) + pow((z2-z1), 2));
dist=sqrt(pow((p2.x-p1.x), 2) + pow((p2.y-p1.y), 2) + pow((p2.z-p1.z), 2));
//printf("\n\nThe distance between (%g,%g,%g) and (%g,%g,%g), is %g", x1, y1, z1, x2, y2, z2, dist);
printf("\n\nThe distance between (%g,%g,%g) and (%g,%g,%g), is %g", p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, dist);
return 0;
}
@Kinjalrk2k
Copy link
Author

the commented sections use the old style without structure...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment