answersLogoWhite

0

Please check following link for primality test. http://en.wikipedia.org/wiki/Primality_test

Following code is not in the optimized form...and it may contains some error please check it carefully before using ... int[] numbers = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }; System.Collections.ArrayList PrimeNumbers = new System.Collections.ArrayList(); Boolean isPrime = false; for (int loop = 0; loop < numbers.Length; loop++) { int intNumberToTest = numbers[loop]; for (int intTest = 2; intTest <= Convert.ToInt32(Math.Sqrt(intNumberToTest)); intTest++) { if (intNumberToTest % intTest == 0) { isPrime = false; break; } else isPrime = true; } if(isPrime) PrimeNumbers.Add(intNumberToTest); }

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

How do you write a program using function that counts the number of vowels in a string in java language?

Use text-editor notepad++


Write the number 12 as the sum of two primes?

12=5+7


What does 'products of its primes' mean?

To write a composite whole number as the product of its prime factors is to write its prime factorization.


How do you write a program in Python to find the first n prime numbers?

One way to do this is to write a function that checks if a number is prime: def isPrime(number): for i in range(2, number): if number%i == 0: return False return True Then create variables to track how many primes have been found and a variable to track which number is being tested for being prime. Increment that variable and test it, and if it is prime print it out (or save it somewhere) and increment the variable being used to track how many primes have been found: targetPrimes = 10 #number of primes to find primesFound = 0 #number of primes found i = 1 while (primesFound &lt; targetPrimes): i += 1 #first number tested is 2 if isPrime(i): print(i) primesFound += 1


How do you write 79.0 as a product of primes?

It is 1*79 = 79.0 because 79 is a prime number


What is it called when you write a composite number as a product of its primes?

It is called the prime factorisation (or prime decomposition) of the composite number.


How do you Write 39 as a product of primes?

To write 39 as a product of primes, you need to factor it into its prime components. Start by dividing 39 by the smallest prime number, which is 3: (39 \div 3 = 13). Since 13 is also a prime number, the prime factorization of 39 is (3 \times 13). Thus, 39 can be expressed as the product of primes: (3 \times 13).


How do you write 1450 as a product of primes?

1450 as a product of primes = 2 * 5 * 5 * 29


How do I write 75 as a product of primes?

5x5x3


How do you write 770 as a prime number?

770 is not prime; however, it can be written as a productof primes:770 = 2*5*7*11.


Write the number 18 as the sum of two primes?

1 + 17 = 18 5 + 13 = 18 7 + 11 = 18


How do you write a number 72 as a product of primes?

72 = 2 x 2 x 2 x 3 x 3