Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- int main () {
- float x1, y1, x2, y2, h1, h2, distance;
- printf("> Enter the source coordinate (x y) (e.g: 2.1 -5): ");
- scanf("%f%f", &x1, &y1);
- printf("> Enter the destination coordinate (x y): ");
- scanf("%f%f", &x2, &y2);
- h1 = x1 - x2;
- h2 = y1 - y2;
- distance = sqrt(h1*h1 + h2*h2);
- printf("\n> Your direction of source coodinate is ");
- if (!x1 && y1) {
- if (y1 > 0)
- printf("Right North.\n");
- else
- printf("Right South.\n");
- } else if (x1 && !y1) {
- if (x1 > 0)
- printf("Right East.\n");
- else
- printf("Right West.\n");
- } else if (x1>0 && y1>0) {
- printf("North East.\n");
- } else if (x1>0 && y1<0) {
- printf("South East.\n");
- } else if (x1<0 && y1<0) {
- printf("South West.\n");
- } else if (x1<0 && y1>0) {
- printf("North West.\n");
- } else {
- printf("undefined. You are in the center of coordinate axis.\n");
- }
- printf("> Your distance between source and destination coordinate is %.3f.", distance);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement