Write a C program that would find the length of a straight line formed by two end points, whose co-ordinates would be given as inputs.
C Programming Language Overview of C Language (Article) Overview of C Language (Program)
3258Program:
/* Program: Write a C program that would find the length of a straight line formed by two end points, whose co-ordinates would be given as inputs. Author: www.atnyla.com */ #include "stdio.h" #include "math.h" int main( ) { float x1, y1, x2, y2, lin_len; /* (x1,y1) and (x2,y2) are co-ordinates of two points */ printf("\n\n Enter x-co-ordinate of first point: "); scanf("%f", &x1); printf("\n Enter y-co-ordinate of first point: "); scanf("%f", &y1); printf("\n\n Enter x-co-ordinate of second point: "); scanf("%f", &x2); printf("\n Enter y-co-ordinate of second point: "); scanf("%f", &y2); lin_len = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)); printf("\n The length of the straight line joining the two points is %f", lin_len); return 0; }
Output:
Enter x-co-ordinate of first point: 2 Enter y-co-ordinate of first point: 2 Enter x-co-ordinate of second point: 6 Enter y-co-ordinate of second point: 8 The length of the straight line joining the two points is 7.211102
Explanation:
None
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.