Simple C Program to Find the Length of a Straight Line

      Using this program user can find the length of a straight line formed by two end points, whose coordinates would be given as inputs.
FORMULA:-√ (( y2− y1)² +( x2− x1)²)


Program:


//C Program to Find the Length of a Straight Line Formed by Two End Points By Slashmycode.com
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x1,x2,y1,y2,line_len;
clrscr();
printf("Enter the x co-ordinate of the first point");
scanf("%f",&x1);
printf("Enter the y co-ordinate of the first point");
scanf("%f",&y1);
printf("Enter the x co-ordinate of the second point");
scanf("%f",&x2);
printf("Enter the y co-ordinate of the second point");
scanf("%f",&y2);
line_len=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
printf("the length of the line is %f",line_len);
//C Program to Find the Length of a Straight Line Formed by Two End Points By Slashmycode.com
getch();

}


Output:


Algorithm:

  1. Start
  2. Define x1,x2,y1,y2,d
  3. Accept the value of x1,y1,x2,y2
  4. Calculate
  5.     d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
  6. Print value of d
  7. Stop

Flowchart:
lenght of line in c flowchart
Click on image to enlarge

2 comments:

  1. Pls can you put the algorithm

    ReplyDelete
    Replies
    1. its given
      Algorithm:

      1 Start
      2 Define x1,x2,y1,y2,d
      3 Accept the value of x1,y1,x2,y2
      4 Calculate
      d=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
      5 Print value of d
      6 Stop

      Delete

Feel free to ask us any question regarding this post