По разделам

 

Решение задачи 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 Просмотров: 9814
While 2 Просмотров: 5647
While 3 Просмотров: 7168
While 4 Просмотров: 8351
While 5 Просмотров: 5545
While 6 Просмотров: 5610
While 7 Просмотров: 4354
While 8 Просмотров: 5105
While 9 Просмотров: 5688
While 10 Просмотров: 4894
While 11 Просмотров: 4101
While 12 Просмотров: 5460
While 13 Просмотров: 3782
While 14 Просмотров: 3776
While 15 Просмотров: 4258
While 16 Просмотров: 5529
While 17 Просмотров: 3906
While 18 Просмотров: 4284
While 19 Просмотров: 3144
While 20 Просмотров: 5122
While 21 Просмотров: 2614
While 22 Просмотров: 4349
While 23 Просмотров: 3116
While 24 Просмотров: 4051
While 25 Просмотров: 2388
While 26 Просмотров: 2455
While 27 Просмотров: 2131
While 28 Просмотров: 2413
While 29 Просмотров: 3033
While 30 Просмотров: 3298

Комментарии

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



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