Jump to content
xisto Community

mattaltepeter

Members
  • Content Count

    3
  • Joined

  • Last visited

Posts posted by mattaltepeter


  1. I am working on a C program to calculate the shortest distance and the rectilinear distance between two points. However, when the program tries to calculate absolute value it doesn't do it correctly every time. any and all help is greatly appreciated

    #include<stdio.h>#include<stdlib.h>int main(){  int x1; //variable to hold the x-coordinate of the first point  int x2; //variable to hold the x-coordinate of the second point  int y1; //variable to hold the y-coordinate of the first point  int y2; //variable to hold the y-coordinate of the second point  float short_distance; //variable to hold the shortest distance  int rectil; //variable to hold the rectilinear distance    printf("Enter the first point: ");  scanf("%d", &x1);  scanf("%d", &y1);  printf("\nEnter the second point: ");  scanf("%d", &x2);  scanf("%d", &y2);  short_distance = sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));  printf("\nShortest distance between points: %.2f\n",short_distance);  rectil = abs(x1-y1) + abs(x2-y2);  printf("Rectilinear distance between points: %d\n", rectil);  return(0);}

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.