Help me please.

Given the problem: On the plane given m points with coordinates Xi, Yi . Determine the number of the point furthest from the origin.

Someone who can help with something, maybe a code, maybe at least a thought.

  • 2
    and what is there to direct? we have the origin (0,0), there are many points, we must calculate the length of all these vectors by one formula and who is greater, that point is more distant. Shl. I'm not worried about you =) you are Elena, so also Victor, such graduate technical universities perfectly =) UPD. the length of the vector is the root of the sum of the squares of its coordinates, so as everything is calculated from 0, everything becomes even simpler =) - Gorets
  • @Gorets, I, of course, do not study perfectly well. Study well. And Elena viktori - because there is so much in life ... I'm afraid. Let's just say, something on the principle of training. I tune myself to win. Go ahead and not be afraid of anything. So here's your taunts or perhaps malice, I don’t know how to call it better, I perceive it not quite to the point. You do not know me. - elenavictory

2 answers 2

Like so:

  Type Tochka = Record X, Y: Real; End; Var M: Array[0..99] Of Tochka; Max: Real; i, N, Ind: Byte; begin Repeat Write('N = '); ReadLn(N); Until (N in [1..99]); Ind:=0; Max:=0; Dec(N); Randomize; WriteLn(' x | y'); For i:=0 To N Do Begin M[i].X:=Random(20)+Random-10; M[i].Y:=Random(20)+Random-10; If (Max<Sqrt(Sqr(M[i].X)+Sqr(M[i].Y))) Then Begin Ind:=i; Max:=Sqrt(Sqr(M[i].X)+Sqr(M[i].Y)); End; WriteLn(' ', M[i].X:2:4, ' | ', M[i].Y:2:4); End; WriteLn; WriteLn(' ', M[Ind].X:2:4, ' | ', M[Ind].Y:2:4); WriteLn('Dist = ', Max:2:4); WriteLn('Number = ', Ind+1); ReadLn; end. 

The distance is based on the Pythagorean theorem.

  • @ DelphiM0ZG, thank you for your help! It's a pity I did not have time to use it. But now there is an opportunity to look at home quietly, and not in a hurry, as everything is done in the standings :) Thanks again! Good luck and all the best! :) - elenavictory
  • But it’s good that they themselves, at least somehow, decided - in programming, as elsewhere, the more practice - the better. You, too, good luck and success in programming. - DelphiM0ZG

The task itself figured out a little. Slightly wrong works. But the teacher still accepted. Of course, I didn’t put the five :) Since the question has already been closed, I can’t write the resulting code normally. But I still want to show what happened.

 {Здесь часть первая:} uses crt; const m=6; type vector = array[1..m] of integer; {matrix = array[1..p,1..p] of real;} var x,y:vector; { c:matrix; } i,j,nmaxX,nmaxY:integer; procedure randomvector(var v:vector; p:integer;min,max:integer); var i:integer; begin { write('input m=');readln(p); } for i:=1 to p do v[i]:=random(max-min+1)+min; end; procedure print( n: integer; var a: vector); var i: integer; begin for i:=1 to n do begin write(a[i]:4); end; writeln; end; procedure new( p:integer; var c:matrix); var i,j:integer; begin for i:=1 to p do for j:=1 to p do if a[i]*b[j]>0 then begin c[i,j]:=c[i,j]+a[i]/(1+b[j]); end else begin c[i,j]:=c[i,j]+b[j]/(1+a[i]); end; end; procedure printt(p: integer; var c: matrix); var i, j: integer; begin for i:=1 to p do begin for j:=1 to p do write(c[i,j]:5:2); writeln; end; writeln; end; function maxx(v:vector;m:integer):integer; var i,max,nmax:integer; begin max:=abs(v[1]);nmax:=1; for i:=2 to m do if abs(v[i])>max then begin max:=abs(v[i]); nmax:=i; end; {write(nmax:3); } maxx:=nmax; end; begin clrscr; randomize; randomvector(x,m,-15,15); writeln('Vector X:'); print(m,x); writeln; randomvector(y,m,-15,15); writeln('Vector Y:'); print(m,y); nmaxX:= maxx(x,m); nmaxY:= maxx(y,m); writeln('max udal tochka s koordinatami :':3);writeln('X=',nmaxX);writeln('Y=',nmaxY);readln; end. 
  • @Angry Bird, thanks for putting the code separately :) - elenavictory