Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project8;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- function NOD( M : integer; F : integer) : integer;
- begin
- while ( M <> F ) do
- if ( M > F) then
- M := M - F
- else
- F := F - M;
- NOD := M;
- end;
- Function FindingFile(): integer;
- var
- CorrectFile: Boolean;
- NameOfFile: String;
- Input : TextFile;
- n, i , k , M , F: integer;
- A : array of integer;
- begin
- repeat
- Write('Введите путь к файлу, с которого хотите считать информацию :');
- Readln(NameOfFile);
- CorrectFile := True;
- try
- AssignFile(Input, NameOfFile);
- Reset(Input);
- if not eof(Input) then
- begin
- ReadLn(Input, n);
- SetLength(A , n);
- for i := 0 to (n - 1) do
- Read(Input, A[i]);
- CloseFile(Input);
- end
- else
- begin
- WriteLn(' Файл оказался пустым ');
- CloseFile(Input) ;
- end;
- except
- CorrectFile := False;
- Writeln('Не удалось найти файл по такому пути', NameOfFile);
- end;
- until CorrectFile;
- k := NOD(A[1] , A[2]);
- for i := 3 to n do
- k := NOD(k, a[i]);
- FindingFile := k;
- end;
- Procedure SaveFile(NameOutput : String ; nod: integer);
- var
- Output: TextFile;
- begin
- Writeln('Введите путь к файлу для записи : ');
- Readln(NameOutput);
- AssignFile(Output,NameOutput);
- Rewrite(Output);
- WriteLn(Output , 'Наибольший общий делитель : ', nod);
- CloseFile(Output);
- ReadLn;
- end;
- var
- k : integer;
- NameOutput : String;
- begin
- WriteLn('Дан массив А, состоящий из n-натуральных чисел.Найти наибольший общий делитель элементов массива.');
- k := FindingFile();
- SaveFile(NameOutput, k);
- ReadLn;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement