smay

Untitled

Feb 7th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.81 KB | None | 0 0
  1. var
  2.   x, n: Integer;
  3.   y: Real;
  4.  
  5. function GetNum(hint: string): Integer;
  6. var
  7.   Tmp: string;
  8.   ErrorCode, Res: Integer;
  9. begin
  10.   repeat
  11.     Write(hint);
  12.     ReadLn(Tmp);
  13.     Val(Tmp, Res, ErrorCode);
  14.     if ErrorCode > 0 then
  15.       WriteLn(Copy(Tmp, 1, ErrorCode - 1), '->', Tmp[ErrorCode], '<-', Copy(Tmp, ErrorCode + 1, Length(Tmp) - ErrorCode));
  16.   until ErrorCode = 0;
  17.   GetNum := Res;
  18. end;
  19.  
  20. function f(const x0, MaxN, CurrentStage: Integer): Real;
  21. var
  22.   Res: Real;
  23. begin
  24.   Res := Cos(Exp(CurrentStage * Ln(x0)));
  25.   if CurrentStage < MaxN then
  26.     Res := Res + f(x0, MaxN, CurrentStage + 1);
  27.   f := Res;
  28. end;
  29.  
  30. begin
  31.   x := GetNum('Vvedite nachalnoe znachenie argumenta: ');
  32.   n := GetNum('Vvedite maksimalnoe znachenie stepeni: ');
  33.   y := f(x, n, 1);
  34.   WriteLn('y=',y:5:2);
  35.   ReadLn;
  36. end.
Add Comment
Please, Sign In to add comment