Write a program in java to accept 20 numbers in an array and display those numbers which are twin prime.
Answers
Answered by
11
Answer:
twin primes between start and end, we use a for loop with counter i ranging between start and end-2. In each iteration, we check if i and i+2 are primes. If so, we output them as twin primes. We fixed the upper limit of i to end-2 because we want only those between start and end. When i is end -2, we check if end -2 and end -2+2 = end are primes. Both these numbers are within the range. Suppose we take the upper limit as end -1. Then we check if end -1 and end -1+2 = end +1 are twin primes. Num+1 is outside the given range. Therefore, we choose the upper range of i as num-2.
Explanation:
I hope it was correct
Similar questions