Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure readNums(var ch1, ch2: longint);
- begin
- read(ch1, ch2); //read 2 nums
- end;
- function FindNOD(var count: longint; in1, in2: longint):longint;
- begin
- count := 0; //firstly count eq 0
- while (in1 <> 0) and (in2 <> 0) do //repeat cycle while inputted values not eq 0
- begin
- if in1 >= in2 then //if 1st inputted value more or eq 2nd then
- in1 := in1 mod in2 //assign to the 1st inputted value remainder of division 1st on 2nd
- else //else
- in2 := in2 mod in1; //assign to the 2st inputted value remainder of division 2st on 1nd
- count := count + 1; //add to the counter variable 1
- end;
- findNOD := in1 + in2; //assign to the function result sum of 1st and 2nd values
- end;
- procedure writeNod(NOD, count: longint);
- begin
- writeln(NOD, ' ', count); //write NOD, space, count of loops in finding NOD function
- end;
- var
- count, in1, in2, NOD: longint;
- begin
- readNums(in1, in2); //read 2 nums
- writeNod(FindNOD(count,in1,in2),count); //Write NOD of this 2 nums and count of loops in finding NOD function
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement