text: Find Prime number just less than and just greater each element of given Array | C # program for the above approach ; Utility function to check for primality of a number X by checking whether X has any factors other than 1 and itself . ; Factor found ; Function to print primes just less than and just greater than of each element in an array ; Traverse the array ; Traverse for finding prime just less than A [ i ] ; Prime just less than A [ i ] found ; Traverse for finding prime just greater than A [ i ] ; Prime just greater than A [ i ] found ; Driver code ; Input ; Function call
code: using System ; class GFG { static bool isPrime ( int X ) { for ( int i = 2 ; i * i <= X ; i ++ ) if ( X % i == 0 ) return false ; return true ; } static void printPrimes ( int [ ] A , int N ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = A [ i ] - 1 ; ; j -- ) { if ( isPrime ( j ) ) { Console . Write ( j + " ▁ " ) ; break ; } } for ( int j = A [ i ] + 1 ; ; j ++ ) { if ( isPrime ( j ) ) { Console . Write ( j + " ▁ " ) ; break ; } } Console . WriteLine ( ) ; } } public static void Main ( ) { int [ ] A = { 17 , 28 } ; int N = A . Length ; printPrimes ( A , N ) ; } }