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.
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.
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.
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.
Source: https://ru.stackoverflow.com/questions/71939/
All Articles