Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure somma_elementi_uguale_numero(in:k,NUMERO; out:somma,valore,posizione)
- var k,numero: integer
- var a0,a1,a2,a3 : integer
- var somma : logical
- var valore, somma_minima, posizione : integer
- begin
- a0:=0;
- a1:=1;
- a2:=2;
- an:=a2+(2*a1)+a0;
- somma_minima:=abs(valore-numero)
- while i<k .AND. .NOT. somma do
- if i%2=0 then
- valore:=valore+an;
- if valore=numero then
- somma=true;
- posizione=i;
- valore=numero;
- else
- if somma_minima>abs(valore-numero) then
- somma_minima := abs(valore-numero)
- posizione := i
- endif
- endif
- endif
- a0:=a1;
- a1:=a2;
- a2:=an;
- an:=a2+2*a1+a0;
- i:=i+1;
- endwhile
- if somma=.FALSE. then
- valore := somma_minima;
- endif
- end
- */
Advertisement
Add Comment
Please, Sign In to add comment