Advertisement
ridjis

papir kolokvijum

May 14th, 2014
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MODULE kol1;
  2. FROM InOut IMPORT WriteInt,WriteLn,WriteString,ReadCard,WriteCard;
  3. FROM RealInOut IMPORT ReadReal,WriteReal;
  4. FROM PolinomL IMPORT Polinom, Anuliraj, Unos, Stampaj, PostaviClan,
  5. Kopiraj, UbaciMonom, DisposePolinom, PolinomNaN, Saberi, Puta;
  6. FROM Storage IMPORT ALLOCATE, DEALLOCATE;
  7.  
  8. VAR p,q,r,a1,a2,a1a2,pq:Polinom;
  9.     pk:CARDINAL;
  10.  
  11. PROCEDURE ParniKoef(p:Polinom):CARDINAL;
  12. VAR temp:Polinom;
  13.     i:CARDINAL;
  14. BEGIN
  15.   i:=0;
  16.   IF p#NIL THEN
  17.     temp:=p;
  18.     WHILE (temp#NIL) DO
  19.       IF (TRUNC(ABS(temp^.k)) MOD 2 = 0) THEN
  20.         INC(i);
  21.       END;
  22.       temp:=temp^.veza;
  23.     END;
  24.   END;
  25.   RETURN i;
  26. END ParniKoef;
  27.  
  28. PROCEDURE Razlike (p:Polinom);
  29. VAR temp:Polinom;
  30.     i:CARDINAL;
  31. BEGIN
  32.   IF (p # NIL) AND (p^.veza # NIL) THEN
  33.     temp:=p;
  34.     WHILE (temp^.veza # NIL) DO
  35.       i:=temp^.st - temp^.veza^.st;
  36.       WriteCard(i,1);
  37.       temp:=temp^.veza;
  38.       WriteLn;
  39.     END;
  40.   ELSE
  41.     WriteString('Polinom ima manje od 2 monoma.');
  42.     WriteLn;
  43.   END;
  44. END Razlike;
  45.  
  46. BEGIN
  47.   WriteString('Unesite polinom p(x): ');
  48.   Unos(p);
  49.   WriteLn;
  50.  
  51.   PostaviClan(19.0,3,q);
  52.   PostaviClan(6.0,1,q);
  53.   PostaviClan(9.0,0,q);
  54.  
  55.   WriteString('p(x)= ');
  56.   Stampaj(p,1);
  57.   WriteLn;
  58.  
  59.   WriteString('q(x)= ');
  60.   Stampaj(q,1);
  61.   WriteLn;
  62.  
  63.   WriteString('Zbir polinoma p i q je r(x)= ');
  64.   Saberi(p,q,r);
  65.   Stampaj(r,1);
  66.   WriteLn;
  67.  
  68.   PostaviClan(2.0,4,a1);
  69.   PostaviClan(3.0,3,a2);
  70.   PostaviClan(8.0,0,a2);
  71.   Puta(a1,a2,a1a2);
  72.   Puta(q,p,pq);
  73.   Saberi(a1a2,pq,r);
  74.   WriteLn;
  75.  
  76.   WriteString('r(x)= ');
  77.   Stampaj(r,1);
  78.   WriteLn;
  79.  
  80.   WriteString('U polinomu ima ');
  81.   pk:=ParniKoef(r);
  82.   WriteCard(pk,1);
  83.   WriteString(' parnih koeficijenata.');
  84.   WriteLn;
  85.  
  86.   WriteString('Razlika stepeni izmedju monoma: ');
  87.   WriteLn;
  88.   Razlike(r);
  89.   WriteLn;
  90.  
  91.   DisposePolinom(p);
  92.   DisposePolinom(q);
  93.   DisposePolinom(r);
  94.   DisposePolinom(a1);
  95.   DisposePolinom(a2);
  96.   DisposePolinom(a1a2);
  97.   DisposePolinom(pq);
  98.  
  99. END kol1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement