training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

distance.c (502B)


      1 /* Exercise 5.45 */
      2 
      3 #include <stdio.h>
      4 
      5 double distance(double, double, double, double);
      6 
      7 int main()
      8 {
      9    double a, b, c, d;
     10 
     11    printf("Give me x1 x2 y1 y2: ");
     12    scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
     13 
     14    printf("Distance is %.2f.\n", distance(a, b, c, d));
     15 
     16    return 0;
     17 } /* E0F main */
     18 
     19 /* Calculate the distance between two points */
     20 double distance(double x1, double y1, double x2, double y2)
     21 {
     22    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); /* taken from the web */
     23 } /* eof distance() */
     24