2 using System.Collections.Generic;
5 using System.Threading.Tasks;
31 List<int> result =
new List<int>();
42 while (factor * factor <= num)
44 if (num % factor == 0)
76 public static int GCD(
int a,
int b)
78 while (a != 0 && b != 0)
86 return a == 0 ? b : a;
104 public static int LCD(
int a,
int b)
119 for (
int i = 1; i < num2; i++)
121 if ((num1 * i) % num2 == 0)
140 public static int CF(
int a,
int b)
145 for (i = 1; i <= j; i++)
146 if (a % i == 0 && b % i == 0)
163 static void Main(
string[] args)
167 int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
168 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
170 bool isContinue =
true;
174 bool aValid =
false, bValid =
false;
175 Console.WriteLine(
"Enter the first number:");
178 sa = Console.ReadLine();
185 Console.WriteLine(
"{0} is not a valid integer.", sa);
187 if (a < 1 || a > 100)
188 Console.WriteLine(
"Please enter a number between 1 and 100.");
193 Console.WriteLine(
"Enter the second number:");
196 sb = Console.ReadLine();
203 Console.WriteLine(
"{0} is not a valid integer.", sb);
205 if (b < 1 || b > 100)
206 Console.WriteLine(
"Please enter a number between 1 and 100.");
217 Console.WriteLine(
"The factors of {0} are:", a);
219 Console.WriteLine(factorsA);
222 Console.WriteLine(
"The factors of {0} are:", b);
224 Console.WriteLine(factorsB);
227 Console.WriteLine(
"The common factors of {0} and {1} are:", a, b);
228 int newCommonFactor =
CF(a, b);
229 string primeCommonFactors =
string.Join(
" ",
Factorization(newCommonFactor));
230 Console.WriteLine(primeCommonFactors);
233 Console.WriteLine(
"The GCF of {0} and {1} is: {2}", a, b,
GCD(a, b));
234 Console.WriteLine(
"The LCD of {0} and {1} is: {2}", a, b,
LCD(a, b));
240 Console.WriteLine(
"\nDo you want to continue? Y/N");
241 string newLoop = Console.ReadLine();
242 if (newLoop[0] ==
'Y' || newLoop[0] ==
'y')
static int GCD(int a, int b)
The greatest common demonitor (GCD) will take in the numbers and will find the GCD value...
static void Main(string[] args)
The main function to run the entire program. This program will ask the user to input two numbers...
static int CF(int a, int b)
The comomn factors will be found when two numbers are input into this
static List< int > Factorization(int num)
The factorization will find the prime numbers, place it in the list and repeat until factorization ca...
static int LCD(int a, int b)
The least common denominator (LCD) will take in the numbers and will find the LCD value...