luc063.c (1001B)
1 /* The X and Y coordinates of 10 different points are entered through the keyboard. Write a program to find the distance of last point from the first point (sum of distances between consecutive points). 2 */ 3 4 /* Let Us C, Chap- 13 (Arrays), Qn No.: B(i) */ 5 6 /* This file is auto-generated by a bot. */ 7 /* This code is not compiled; it is for reference only. */ 8 9 10 #include <stdio.h> 11 #include <math.h> 12 #include <stdlib.h> 13 14 int main() 15 { 16 double x[10], y[10]; 17 double total_distance = 0.0; 18 int i; 19 20 printf("Enter coordinates (x, y) for 10 points:\n"); 21 for (i = 0; i < 10; i++) 22 { 23 printf("Point %d: ", i + 1); 24 scanf("%lf %lf", &x[i], &y[i]); 25 } 26 27 // Sum of distances between consecutive points P(i) and P(i+1) 28 for (i = 0; i < 9; i++) 29 { 30 double dx = x[i+1] - x[i]; 31 double dy = y[i+1] - y[i]; 32 total_distance += sqrt(dx*dx + dy*dy); 33 } 34 35 printf("\nTotal distance from first to last point: %.2f\n", total_distance); 36 37 return 0; 38 }