Advertisement
patryk

Symbol Newtona v.1.0

Oct 23rd, 2013
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.31 KB | None | 0 0
  1. program ConsoleExceptionHandling;
  2. {$APPTYPE CONSOLE}
  3.  
  4. uses
  5.   SysUtils, Crt;
  6.  
  7. procedure ExecuteProgram;
  8. begin
  9.   // Program does something
  10.   raise Exception.Create('Unforeseen exception');
  11. end;
  12.  
  13. function silnia(x:Integer):Comp;
  14.  
  15.  begin
  16.   if x=0 then
  17.    silnia:=1
  18.   else
  19.    silnia:= silnia(x-1) * x;
  20.  end;
  21. var n, k:Integer;
  22. var c:Boolean;
  23.  
  24. begin
  25.   try
  26.  c:=false;
  27.  while c=false do
  28.   begin
  29.  
  30.    while c=false do
  31.     begin
  32.  
  33.      Write('[in]$ Wpisz n: ');
  34.      ReadLn(n);
  35.      if (n <= 0) or (n>100) then
  36.       WriteLn('[out]$ Blad! ( n powinien nalezec do przedzialu (0, 100> )')
  37.      else
  38.       c:=true;
  39.     end;
  40.  
  41.    c:=false;
  42.    while c=false do
  43.     begin
  44.  
  45.      Write('[in]$ Wpisz k: ');
  46.      ReadLn(k);
  47.      if (k<=0) or (k>100) then
  48.       WriteLn('[out]$ Blad! ( k powinno nalezec do przedzialu (0, 100> )')
  49.      else
  50.       c:=true;
  51.     end;
  52.    c:=false;
  53.  
  54.    if n>=k then
  55.     c:=true
  56.    else
  57.     begin
  58.      ClrScr;
  59.      WriteLn('[out]$ Blad! (k>n)');
  60.     end;
  61.   end;
  62. WriteLn;
  63. Write('[out]$ Wartosc symbolu Newtona wynosi: ', (silnia(n) )/ ( silnia(k) * silnia(n-k) ) );
  64. ReadLn;
  65.   except
  66.     // Handle error condition
  67.     WriteLn('Program terminated due to an exception');
  68.     // Set ExitCode &lt;&gt; 0 to flag error condition (by convention)
  69.     ExitCode := 1;
  70.   end;
  71.  
  72. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement