Write a c program to calculate the distance between two points using formula √ (( y2− y1)² +( x2− x1)²)

#include<stdio.h>
#include<math.h>

int main ()
     {
        int  x1, x2, y1, y2;
        float  r;
        printf( "Enter Point (x1,y1): " );
        scanf( "%d" ,&x1);
        scanf( "%d" ,&y1);
        printf( "\nEnter Point (x2,y2): " );
        scanf( "%d%d" ,&x2,&y2);
        r = sqrt(pow((y2-y1),2) + pow((x2-x1),2));
        printf( "\nDistance= %f" ,r);
        return  0;
     }

9 comments:

  1. With this code , can I calculate the distance between two district ??

    ReplyDelete
    Replies
    1. This program finds only straight distance between two points. If you need straight distance between two districts and you have known points for them, then you can gain the result from this program.

      Delete
  2. ex1setb1.c:11:2: error: too few arguments to function ‘pow’
    ex1setb1.c:11:2: error: too few arguments to function ‘pow’
    ex1setb1.c:11:8: error: subscripted value is neither array nor pointer
    what to do sir??

    ReplyDelete
    Replies
    1. Please write your code... So that we can judge if you have any typo.

      Delete