Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- int[] nums1 = { 4, 6, 8 };
- Console.WriteLine("Original array elements:");
- for (int i = 0; i < nums1.Length; i++)
- {
- Console.Write(nums1[i] + " ");
- }
- Console.WriteLine("\nLCM of the numbers of the said array of positive integers: " + test(nums1));
- int[] nums2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- Console.WriteLine("\nOriginal array elements:");
- for (int i = 0; i < nums2.Length; i++)
- {
- Console.Write(nums2[i] + " ");
- }
- Console.WriteLine("\nLCM of the numbers of the said array of positive integers: " + test(nums2));
- int[] nums3 = { 48, 72, 108 };
- Console.WriteLine("\nOriginal array elements:");
- for (int i = 0; i < nums3.Length; i++)
- {
- Console.Write(nums3[i] + " ");
- }
- Console.WriteLine("\nLCM of the numbers of the said array of positive integers: " + test(nums3));
- }
- static int gcd(int n1, int n2)
- {
- if (n2 == 0)
- {
- return n1;
- }
- else
- {
- return gcd(n2, n1 % n2);
- }
- }
- public static int test(int[] numbers)
- {
- return numbers.Aggregate((S, val) => S * val / gcd(S, val));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement