Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- typedef struct{
- int x,y;
- int o;
- }Punct;
- void citire(int n,Punct *v){
- int i;
- for(i=1;i<=n;i++){
- printf("x=");
- scanf("%d",&v[i].x);
- printf("y=");
- scanf("%d",&v[i].y);
- v[i].o=0;
- }
- }
- int minPos(int k,int n,Punct *v){
- float l1;
- int i;
- for(i=0;i<=n;i++){
- if(v[i].o==0){
- l1=sqrt(pow(abs(v[k].x)-abs(v[i].x),2)+pow(abs(v[k].y)-abs(v[i].y),2));
- break;
- }
- }
- //printf("%f\n\n",l1);
- int poz=0;
- for(i=1;i<=n;i++){
- if(v[i].o==0){
- float l2=sqrt(pow(abs(v[k].x)-abs(v[i].x),2)+pow(abs(v[k].y)-abs(v[i].y),2));
- if(l1>=l2){
- poz=i;
- l1=l2;
- }
- }
- }
- v[poz].o=1;
- printf("(%d,%d)\n",v[poz].x,v[poz].y);
- return poz;
- }
- int main(){
- int n;
- int pos=0;
- Punct v[1000];
- printf("nr de puncte:");
- scanf("%d",&n);
- citire(n,v);
- int i=0;
- v[i].x=0;
- v[i].y=0;
- v[i].o=1;
- printf("(%d,%d)\n",v[0].x,v[0].y);
- while(i<n){
- //cat timp avem puncte
- pos=minPos(pos,n,v);
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement