Check if number can be made prime by deleting a single digit | C # implementation to check if a number becomes prime by deleting any digit ; Function to check if N is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to delete character at index i from given String str ; Deletes character at position 4 ; Function to check if a number becomes prime by deleting any digit ; Converting the number to String ; length of String ; number should not be of single digit ; Loop to find all numbers after deleting a single digit ; Deleting ith character from the String ; converting String to int ; Driver Code
using System ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static String deleteIth ( String str , int i ) { str = str . Substring ( 0 , i ) + str . Substring ( i + 1 ) ; return str ; } static bool isPrimePossible ( int N ) { String s = String . Join ( " " , N ) ; int l = s . Length ; if ( l < 2 ) return false ; for ( int i = 0 ; i < l ; i ++ ) { String str = deleteIth ( s , i ) ; int num = Int32 . Parse ( str ) ; if ( isPrime ( num ) ) return true ; } return false ; } public static void Main ( String [ ] args ) { int N = 610 ; if ( isPrimePossible ( N ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }