Advertisement
pdaogu

Ex6.5

Oct 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4.  
  5. int main () {
  6.     float x1, y1, x2, y2, h1, h2, distance;
  7.     printf("> Enter the source coordinate (x y) (e.g: 2.1 -5): ");
  8.     scanf("%f%f", &x1, &y1);
  9.     printf("> Enter the destination coordinate (x y): ");
  10.     scanf("%f%f", &x2, &y2);
  11.     h1 = x1 - x2;
  12.     h2 = y1 - y2;
  13.     distance = sqrt(h1*h1 + h2*h2);
  14.     printf("\n> Your direction of source coodinate is ");
  15.     if (!x1 && y1) {
  16.         if (y1 > 0)
  17.             printf("Right North.\n");
  18.         else
  19.             printf("Right South.\n");
  20.     } else if (x1 && !y1) {
  21.         if (x1 > 0)
  22.             printf("Right East.\n");
  23.         else
  24.             printf("Right West.\n");
  25.     } else if (x1>0 && y1>0) {
  26.         printf("North East.\n");
  27.     } else if (x1>0 && y1<0) {
  28.         printf("South East.\n");
  29.     } else if (x1<0 && y1<0) {
  30.         printf("South West.\n");
  31.     } else if (x1<0 && y1>0) {
  32.         printf("North West.\n");
  33.     } else {
  34.         printf("undefined. You are in the center of coordinate axis.\n");
  35.     }
  36.     printf("> Your distance between source and destination coordinate is %.3f.", distance);
  37.     getch();
  38.     return 0;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement