Advertisement
rowers

funkcje

Jan 9th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.09 KB | None | 0 0
  1. {program project1;}
  2.  
  3.  
  4. {var
  5.   x,i:integer;
  6.  
  7. function lustro(n:integer):string;
  8.  
  9. begin
  10.      repeat
  11.        begin
  12.            n:=n+chr(ord('0')+i);
  13.            n:=n div x;
  14.            i:=i+1;
  15.        end;
  16.      until (n mod x=0);
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. begin
  24.   writeln('Podaj liczbe: ');
  25.   readln(n);
  26.   writeln('Odwrotna liczba to: ', lustro(x));
  27.  
  28.  
  29.  
  30.  
  31. readln();
  32. end.}
  33.  
  34.  
  35. {var x:integer;
  36. function lustro(n:integer):string;
  37.  
  38. var s:string;
  39.     r:integer;
  40.  
  41. begin
  42.      s:='';
  43.      while(n<>0) do
  44.      begin
  45.           r:=n mod 10;
  46.           s:=s+chr(ord('0')+r);
  47.           n:=n div 10;
  48.      end;
  49.      lustro:=s;
  50. end;
  51.  
  52.  
  53.  
  54. begin
  55.   writeln('Podaj liczbe: ');
  56.   readln(x);
  57.   writeln('Odwrotna liczba to: ', lustro(x));
  58.  
  59.  
  60.  
  61.  
  62. readln();
  63. end. }
  64.  
  65.  
  66. program project2;
  67. var
  68.   plik:text;
  69.   tekst:string;
  70.  
  71. function suma(plik:string):integer;
  72.  
  73. var
  74.   a,i:integer;
  75.  
  76. begin
  77.   a:=0;
  78.   reset(plik);
  79.   for i:=0 to length(plik) do
  80.   begin
  81.     if(ord(plik[i])>=0) and (ord(plik[i])<=9) then
  82.     begin
  83.       a:=a+ord(plik[i]);
  84.     end;
  85.   end;
  86.   suma:=a;
  87.   end;
  88.  
  89. begin
  90.   assign(plik, 'liczby.txt');
  91.   reset(plik);
  92.   while(eof(plik)) do
  93.   begin
  94.     read(plik, liczba);
  95.     tekst:=tekst+liczba;
  96.   end;
  97.     close(plik);
  98.     writeln('Suma = ',suma(tekst));
  99. end.}
  100.  
  101. function suma(plik:string):integer;
  102. var
  103.   p:text;
  104.   s:integer;
  105.   z:char;
  106.  
  107. begin
  108.   s:=0;
  109.   assign(p, plik);
  110.   reset(p);
  111.   while(not eof(p)) do
  112.   begin
  113.     read(p,z);
  114.     if (z in ['0'..'9']) then
  115.     s:=s+(ord(z)-ord('0'));
  116.   end;
  117.   close(p);
  118.   suma:=s;
  119. end;
  120.  
  121. begin
  122.   writeln(suma('liczby.txt'));
  123.   readln();
  124. end.  
  125.  
  126.  
  127.  
  128.  
  129. program project3;
  130.  
  131. function suma(plik:string):integer;
  132.  
  133. var
  134.   a,i:integer;
  135.   plik:text;
  136.   z:char;
  137.   p1:file of integer;
  138.  
  139. begin
  140.   a:=0;
  141.   assign(plik, plik);
  142.   assign(p1, 'liczby.txt');
  143.   rewrite(p1);
  144.   reset(plik);
  145.   while (not eof(plik)) do
  146.   begin
  147.     read(plik, liczba);
  148.     if(liczba in ['0'..'9']) then
  149.               a:=a+(ord(liczba) -ord('0');
  150.               write(ord(liczba) - ord('0');
  151.   end;
  152.  
  153.   close(plik);
  154.   close(p1);
  155.   writeln;
  156.   writeln;
  157.   suma:=a;
  158. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement