Fenrir112

Ряды для Наташи версия 01

Dec 24th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.23 KB | None | 0 0
  1. const
  2.    MAX = 100;
  3.  
  4. type mas = array [1..MAX] of real;
  5.  
  6. var
  7.    N, epsL, err : integer;
  8.    x, resS, resY : mas;
  9.    eps : real;
  10.    f : text;
  11.    fName, epsS : string;
  12.    
  13. function ryad (x, eps : real) : real;
  14. var
  15.    a, b, c, Sum : real;
  16.    i            : integer;
  17. begin
  18.    Sum := 0;
  19.    i := 0;
  20.    a := Cos (i * x);
  21.    b := 1;
  22.    repeat
  23.       inc (i);
  24.       a := cos (i * x);
  25.       b := b * i;
  26.       c := a / b;
  27.       Sum := Sum + c;
  28.    until c < eps;
  29.    ryad := Sum;
  30. end;
  31.  
  32. procedure input;
  33. var
  34.    name : string;
  35. begin
  36.    write ('Введите имя файла для записи или нажмите Enter: ');
  37.    readln(name);
  38.    if name = ''
  39.    then
  40.       fName := 'Отчет.txt'
  41.    else
  42.       fname := name+'.txt';
  43.    writeln('Запись отчета в файл: ', fName);
  44.    assign (f, fName);
  45.    rewrite (f);
  46.    write ('Введите N : ');
  47.    readln (N);
  48.    write ('Введите точность : ');
  49.    readln (epsS);
  50.    Val (epsS, eps, err);
  51.    epsL := epsS.Length-2;
  52. end;
  53.  
  54. procedure inputX (N : integer);
  55. var
  56.    i : integer;
  57. begin
  58.    writeln('Вводите значения x только из промежутка [0.1 ; 1]');
  59.    for i := 1 to N do
  60.    begin
  61.       write ('x[', i,'] = ');
  62.       readln (x[i]);
  63.    end;
  64. end;
  65.  
  66. function resultS (x : mas; N : integer) : mas;
  67. var
  68.    i : integer;
  69.    a : mas;
  70. begin
  71.    for i := 1 to N do
  72.       a[i] := ryad (x[i], eps);
  73.    resultS := a;
  74. end;
  75.  
  76. function resultY (x : mas; N : integer) : mas;
  77. var
  78.    i : integer;
  79.    a : mas;
  80. begin
  81.    for i := 1 to N do
  82.       a[i] := exp (cos(x[i])) * cos(sin(x[i]));
  83.    resultY := a;
  84. end;
  85.  
  86. procedure output (x, S, y : mas; N : integer);
  87. var
  88.    i : integer;
  89. begin
  90.    writeln(f, '   N |  x  |    S    |    y    ');
  91.    for i := 1 to N do
  92.    begin
  93.       writeln(f, '-----+-----+---------+---------');
  94.       writeln (f, i : 5, '|', x[i] : 5, '|', S[i] : 9 : epsL, '|', y[i] : 9 : epsL);
  95.    end;
  96.    writeln ('Результат записан в файл: ', fName);
  97.    close (f);
  98.    writeln ('Работа программы успешно завершена');
  99. end;
  100.  
  101. begin
  102.    input;
  103.    inputX (N);
  104.    ResS := resultS (x, N);
  105.    ResY := resultY (x, N);
  106.    output (x, ResS, ResY, N);
  107. end.
Advertisement
Add Comment
Please, Sign In to add comment