Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <math.h>
- struct ToaDo
- {
- float x;
- float y;
- };
- float tinhKhoangCach ( ToaDo A, ToaDo B)
- {
- float result = sqrt( (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
- return result;
- }
- void NhapToaDo( ToaDo & A)
- {
- printf("Hoanh do: ");
- scanf("%f", &A.x);
- printf("Tung do: ");
- scanf("%f", &A.y);
- }
- void inputArrayPoint( ToaDo* A, int n)//n la so phan tu cua mang
- {
- for ( unsigned int i = 0; i < n; i++)
- {
- printf("Nhap diem thu %d: \n", i);
- NhapToaDo(A[i]);
- }
- }
- ToaDo distanceToO( ToaDo *A, int n)//n la so phan tu cua mang ToaDo A
- {
- ToaDo O;
- O.x = 0;
- O.y = 0;
- float Min = tinhKhoangCach(A[0], O);
- ToaDo TDMin;
- TDMin = A[0];
- for ( unsigned int i = 1; i < n; i++)
- {
- float temp = tinhKhoangCach(A[i], O);
- if ( Min > temp)
- {
- Min = temp;
- TDMin = A[i];
- }
- }
- return TDMin;
- }
- void main()
- {
- ToaDo A[100];
- int n;
- printf("Nhap so phan tu mang toa do: ");
- scanf( "%d", &n);
- inputArrayPoint(A, n);
- ToaDo X = distanceToO(A,n);
- printf("\nDiem gan O nhat la: (%.2f , %.2f)", X.x, X.y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement