Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <malloc.h>
- #include<math.h>
- struct vector_type
- {
- double x_start = 0, y_start = 0, x_end = 0, y_end = 0, length = 0;
- };
- double get_length_x(double x_s, double x_en)
- {
- return x_en - x_s;
- }
- double get_length_y(double y_s, double y_en)
- {
- return y_en - y_s;
- }
- double get_length(double x, double y)
- {
- return sqrt(x*x + y*y);
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int num;
- double temp_len_X, temp_len_Y;
- scanf("%d", &num);
- struct vector_type *vector_arr = (struct vector_type*)malloc(sizeof(struct vector_type) * num);
- for (int i = 0; i < num; i++)
- {
- scanf("%lf%lf%lf%lf", &vector_arr[i].x_start, &vector_arr[i].y_start, &vector_arr[i].x_end, &vector_arr[i].y_end);
- temp_len_X = get_length_x(vector_arr[i].x_start, vector_arr[i].x_end);
- temp_len_Y = get_length_y(vector_arr[i].y_start, vector_arr[i].y_end);
- vector_arr[i].length = get_length(temp_len_X, temp_len_Y);
- printf("%lf", vector_arr[i].length);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement