Advertisement
aimon1337

Untitled

May 13th, 2020
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5.  
  6. typedef struct{
  7.     int x,y;
  8.     int o;
  9. }Punct;
  10.  
  11.  
  12. void citire(int n,Punct *v){
  13.     int i;
  14.     for(i=1;i<=n;i++){
  15.         printf("x=");
  16.         scanf("%d",&v[i].x);
  17.         printf("y=");
  18.         scanf("%d",&v[i].y);
  19.         v[i].o=0;
  20.     }
  21. }
  22. int minPos(int k,int n,Punct *v){
  23.     float l1;
  24.     int i;
  25.     for(i=0;i<=n;i++){
  26.         if(v[i].o==0){
  27.             l1=sqrt(pow(v[k].x-v[i].x,2)+pow(v[k].y-v[i].y,2));
  28.             break;
  29.         }
  30.     }
  31.  
  32.    //printf("%f\n\n",l1);
  33.     int poz=0;
  34.     for(i=1;i<=n;i++){
  35.         if(v[i].o==0){
  36.             float l2=sqrt(pow(v[k].x-v[i].x,2)+pow(v[k].y-v[i].y,2));
  37.             if(l1>=l2){
  38.                 poz=i;
  39.                 l1=l2;
  40.             }
  41.         }
  42.     }
  43.     v[poz].o=1;
  44.     printf("(%d,%d)\n",v[poz].x,v[poz].y);
  45.     return poz;
  46. }
  47. int main(){
  48.     int n;
  49.         int pos=0;
  50.     Punct v[1000];
  51.     printf("nr de puncte:");
  52.     scanf("%d",&n);
  53.     citire(n,v);
  54.     int i=0;
  55.     v[i].x=0;
  56.     v[i].y=0;
  57.     v[i].o=1;
  58.     printf("(%d,%d)\n",v[0].x,v[0].y);
  59.     while(i<n){
  60.         //cat timp avem puncte
  61.         pos=minPos(pos,n,v);
  62.         i++;
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement