Advertisement
Denny707

Untitled

May 10th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.84 KB | None | 0 0
  1. procedure somma_elementi_uguale_numero(in:k,NUMERO; out:somma,valore,posizione)
  2.     var k,numero: integer
  3.     var a0,a1,a2,a3 : integer
  4.     var somma : logical
  5.     var valore, somma_minima, posizione : integer
  6.    
  7.     begin
  8.         a0:=0;
  9.         a1:=1;
  10.         a2:=2;
  11.         an:=a2+(2*a1)+a0;
  12.         somma_minima:=abs(valore-numero)
  13.        
  14.         while i<k .AND. .NOT. somma  do
  15.             if i%2=0 then
  16.                 valore:=valore+an;
  17.                 if valore=numero then
  18.                     somma=true;
  19.                     posizione=i;
  20.                     valore=numero;
  21.                 else
  22.                     if somma_minima>abs(valore-numero) then
  23.                         somma_minima := abs(valore-numero)
  24.                         posizione := i
  25.                     endif
  26.                 endif
  27.             endif
  28.             a0:=a1;
  29.             a1:=a2;
  30.             a2:=an;
  31.             an:=a2+2*a1+a0;
  32.             i:=i+1;
  33.         endwhile
  34.         if somma=.FALSE. then
  35.             valore := somma_minima;
  36.         endif
  37.  
  38.     end
  39. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement