public int ApplyFirstMethod(int number) { var isPrime = new IsPrime(); var result = new bool(); var smallPrimeNumber = new int(); for (int i = number - 1; i >= 0; i--) { isPrime.CheckIsPrimeNumber(i, result); if (result == true) { smallPrimeNumber = i; break; } } return(smallPrimeNumber); }
public int ApplySecondMethod(int number, int smallPrimeNumber) { var isPrime = new IsPrime(); var result = new bool(); int[] primeNumbers = new int[number]; int index = 0; for (int i = 1; i < number; i++) { isPrime.CheckIsPrimeNumber(i, result); if (result == true) { primeNumbers[index] = i; index++; } } smallPrimeNumber = primeNumbers[primeNumbers.Length - 1]; return(smallPrimeNumber); }
static void Main(string[] args) { var number = 10; var result = new bool(); var result1 = new int(); var result2 = new int(); var isPrime = new IsPrime();//publisher var firstMethod = new FirstMethod(); var secondMethod = new SecondMethod(); isPrime.IsPrimeNumber += firstMethod.OnIsPrimeNumber; isPrime.IsPrimeNumber += secondMethod.OnIsPrimeNumber; isPrime.CheckIsPrimeNumber(number, result); System.Console.WriteLine(number + " is prime number: " + result); result1 = firstMethod.ApplyFirstMethod(number); System.Console.WriteLine("[First method]: the biggest prime number smaller then " + number + " is: " + result1); result2 = secondMethod.ApplySecondMethod(number, result2); System.Console.WriteLine("[Second method]: the biggest prime number smaller then " + number + " is: " + result2); }