Thread: C Program - Accept rectangular points and calculate distance between

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    98

    C Program - Accept rectangular points and calculate distance between

    I am writing a c program that accepts two coordinate points from a rectangle, using a function distance, calculates the distance between using the formula distance = sqrt (x2-x1)^2+(y2-y1)^2
    I know my beginning code is off base but I am just beginning in code and struggling to find correct codes.

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>
    #pragma warning (disable:4996)
    int main()
    {
      float x1, x2, y1, y2, midpoint, xtotal, ytotal;
      printf("Enter the first x coordinate: ");
      scanf("%f", &x1);
      printf("Enter the first y coordinate: ");
      scanf("%f", &y1);
      printf("Enter the second x coordinate: ");
      scanf("%f", &x2);
      printf("Enter the second y coordinate: ");
      scanf("%f", &y2);
      xtotal = (x2 - x1) * (x2 - x1);
      ytotal = (y2 - y1) * (y2 - y1);
      midpoint = sqrt(xtotal) + (ytotal);
      printf("The distance of the coordinate is %f", midpoint);
       return 0;
      system("pause");
    }
    Last edited by Salem; 03-06-2012 at 08:43 PM. Reason: demunging the horrible choice of tags - paste as TEXT in future

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A program that can only accept a numerical value?
    By Bano360 in forum C Programming
    Replies: 4
    Last Post: 11-15-2010, 07:55 PM
  2. help! calculate arbitrary number of floating points
    By cakestler in forum C Programming
    Replies: 5
    Last Post: 02-26-2009, 02:47 PM
  3. Rectangular Approximation Program Help
    By Noah in forum C Programming
    Replies: 4
    Last Post: 03-15-2006, 02:23 PM
  4. Segfaulting Distance Program
    By radiohead in forum C Programming
    Replies: 2
    Last Post: 01-09-2006, 08:48 PM
  5. Distance Formula in my program..... I need help fast!!!
    By Mackology101 in forum C Programming
    Replies: 3
    Last Post: 09-23-2004, 10:10 PM