using System;
namespace ConsoleApp2
{
class Program
static int gcd(int a, int b)
if (a == 0)
return b;
return gcd(b % a, a);
}
static int findGCD(int[] arr, int n)
int result = arr[0];
for (int i = 1; i < n; i++)
result = gcd(arr[i], result);
return result;
static void Main(string[] args)
Console.WriteLine("Введите 4 числа");
int a, b, c, d;
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
d = Convert.ToInt32(Console.ReadLine());
int[] arr = {a,b,c,d};
int n = arr.Length;
Console.Write(findGCD(arr, n));
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
using System;
namespace ConsoleApp2
{
class Program
{
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static int findGCD(int[] arr, int n)
{
int result = arr[0];
for (int i = 1; i < n; i++)
result = gcd(arr[i], result);
return result;
}
static void Main(string[] args)
{
Console.WriteLine("Введите 4 числа");
int a, b, c, d;
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
d = Convert.ToInt32(Console.ReadLine());
int[] arr = {a,b,c,d};
int n = arr.Length;
Console.Write(findGCD(arr, n));
}
}
}