Write a program that takes input the X and Y coordinate of 10 differet points and find the total distance between first and last point that is the sum of distances between two consecutive points.

#include<stdio.h>
#include<math.h>
main()
{ int i,sqr;
double x[10],y[10],x1,y1 ,dist, sum=0.0;
printf("\nEnter the coordinates of 3 points,in the form (X,Y):: ");
for(i=0;i<10;i++)
scanf("%lf %lf",&x[i],&y[i]);
for(i=0;i<9;i++)
{ x1=pow((x[i+1]-x[i]),2.0);
y1=pow((y[i+1]-y[i]),2.0);
dist=sqrt(x1+y1);
sum+=dist;
}
printf("\nDistance is= %lf\n",sum);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s