По разделам

 

Решение задачи While 23


Даны целые положительные числа A и B. Найти их наибольший
общий делитель (НОД), используя алгоритм Евклида:
НОД(A, B) = НОД(B, A mod B), если B 6= 0; НОД(A, 0) = A

Код (C/C++)

#include <stdio.h>
int main(void)
{
   int n;
   printf("N:");
   scanf ("%i", &n);
   int k=2;
   while((k<n-1) & ((n%k)!=0) ){
       ++k;
   }
   printf("%s\n",((n%k)!=0)?"True":"False");
   return 0;
}

Код (Python)

import random

A = random.randrange(1,1000)
B = random.randrange(1,1000)
print("A = {0}, B = {1}".format(A,B))
while B > 0:
    A,B = B,A%B
print("НОД: ",A)
									

Код (Pascal)

program While23;
var
  A,B :Integer;
begin
  Write('Введите число A: ');
  Readln(A);
  Write('Введите число B: ');
  Readln(B);
  while (A<>0) and (B<>0) do
   begin
    if a>b then A:=(a mod b)
    else B:=(B mod A);
   end;
  Writeln(A+B);
end.
									




While. Абрамян
While 1 Просмотров: 9452
While 2 Просмотров: 5363
While 3 Просмотров: 6909
While 4 Просмотров: 7994
While 5 Просмотров: 5271
While 6 Просмотров: 5350
While 7 Просмотров: 4152
While 8 Просмотров: 4888
While 9 Просмотров: 5431
While 10 Просмотров: 4650
While 11 Просмотров: 3909
While 12 Просмотров: 5270
While 13 Просмотров: 3562
While 14 Просмотров: 3566
While 15 Просмотров: 4028
While 16 Просмотров: 5061
While 17 Просмотров: 3697
While 18 Просмотров: 4076
While 19 Просмотров: 2959
While 20 Просмотров: 4884
While 21 Просмотров: 2443
While 22 Просмотров: 4135
While 23 Просмотров: 2921
While 24 Просмотров: 3861
While 25 Просмотров: 2244
While 26 Просмотров: 2321
While 27 Просмотров: 1971
While 28 Просмотров: 2268
While 29 Просмотров: 2849
While 30 Просмотров: 3127

Комментарии

Чтобы написать комментарии вам нужно войти в систему или зарегистрироваться



Заявка на расчет