codeparrot/xlcost-text-to-code huggingface dataset:
N | C # program to find N - th term in George Cantor set of rational number ; let i = numerator ; let j = denominator ; to keep the check of no . of terms ; loop till k is not equal to n ; check if k is already equal to N then the first term is the required rational number ; loop for traversing from right to left downwards diagonally ; loop for traversing from left to right upwards diagonally ; Driver code
using System ; class GFG { static void georgeCantor ( int n ) { int i = 1 ; int j = 1 ; int k = 1 ; while ( k < n ) { j ++ ; k ++ ; if ( k == n ) break ; while ( j > 1 && k < n ) { i ++ ; j -- ; k ++ ; } if ( k == n ) break ; i ++ ; k ++ ; if ( k == n ) break ; while ( i > 1 && k < n ) { i -- ; j ++ ; k ++ ; } } Console . WriteLine ( " N - th ▁ term ▁ : ▁ " + i + " / " + j ) ; } public static void Main ( ) { int n = 15 ; georgeCantor ( n ) ; } }
Number is divisible by 29 or not | C # program to demonstrate above method to check divisibility by 29. ; Returns true if n is divisible by 29 else returns false . ; add the lastdigit * 3 to renaming number until number comes only 2 digit ; return true if number is divisible by 29 another ; Driver code
using System ; class GFG { static bool isDivisible ( long n ) { while ( n / 100 > 0 ) { int last_digit = ( int ) n % 10 ; n /= 10 ; n += last_digit * 3 ; } return ( n % 29 == 0 ) ; } public static void Main ( ) { long n = 348 ; if ( isDivisible ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Solve the Linear Equation of Single Variable | C # program to solve the given equation ; Function to solve the given equation ; Traverse the equation ; For cases such as : x , - x , + x ; Flip sign once ' = ' is seen ; There may be a number left in the end ; For infinite solutions ; For no solution ; x = total sum / coeff of x ' - ' sign indicates moving numeric value to right hand side ; Driver code
using System ; class GFG { static string solveEquation ( string equation ) { int n = equation . Length , sign = 1 , coeff = 0 ; int total = 0 , i = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( equation [ j ] == ' + ' equation [ j ] == ' - ' ) { if ( j > i ) total += sign * Int32 . Parse ( equation . Substring ( i , j - i ) ) ; i = j ; } else if ( equation [ j ] == ' x ' ) { if ( ( i == j ) equation [ j - 1 ] == ' + ' ) coeff += sign ; else if ( equation [ j - 1 ] == ' - ' ) coeff -= sign ; else coeff += sign * Int32 . Parse ( equation . Substring ( i , j - i ) ) ; i = j + 1 ; } else if ( equation [ j ] == ' = ' ) { if ( j > i ) total += sign * Int32 . Parse ( equation . Substring ( i , j - i ) ) ; sign = - 1 ; i = j + 1 ; } } if ( i < n ) total += sign * Int32 . Parse ( equation . Substring ( i ) ) ; if ( coeff == 0 && total == 0 ) return " Infinite ▁ solutions " ; if ( coeff == 0 && total != 0 ) return " No ▁ solution " ; int ans = - total / coeff ; return " x ▁ = ▁ " + ans . ToString ( ) ; } static void Main ( ) { string equation = " x + 5-3 + x = 6 + x - 2" ; Console . Write ( solveEquation ( equation ) ) ; } }
Check if a given number is Pronic | Efficient Approach | C # program to check if a number is pronic or not ; Function to check Pronic Number ; Checking Pronic Number by multiplying consecutive numbers ; Driver Code
using System ; class GFG { static bool pronic_check ( int n ) { int x = ( int ) ( Math . Sqrt ( n ) ) ; if ( x * ( x + 1 ) == n ) return true ; else return false ; } public static void Main ( ) { int n = 56 ; if ( pronic_check ( n ) == true ) Console . Write ( " YES " ) ; else Console . Write ( " NO " ) ; } }
Check if given number is perfect square | C # program for the above approach ; If ceil and floor are equal the number is a perfect square ; Driver Code
using System ; class GFG { static void checkperfectsquare ( int n ) { if ( Math . Ceiling ( ( double ) Math . Sqrt ( n ) ) == Math . Floor ( ( double ) Math . Sqrt ( n ) ) ) { Console . Write ( " perfect ▁ square " ) ; } else { Console . Write ( " not ▁ a ▁ perfect ▁ square " ) ; } } public static void Main ( ) { int n = 49 ; checkperfectsquare ( n ) ; } }
Writing power function for large numbers | C # program to compute factorial of big numbers ; Maximum number of digits in output ; This function multiplies x with the number represented by res [ ] . res_size is size of res [ ] or number of digits in the number represented by res [ ] . This function uses simple school mathematics for multiplication . This function may value of res_size and returns the new value of res_size ; Initialize carry ; One by one multiply n with individual digits of res [ ] ; Store last digit of ' prod ' in res [ ] ; Put rest in carry ; Put carry in res and increase result size ; This function finds power of a number x ; printing value "1" for power = 0 ; Initialize result ; Multiply x n times ( x ^ n = x * x * x ... . n times ) ; Driver code
using System ; class GFG { static int MAX = 100000 ; static int multiply ( int x , int [ ] res , int res_size ) { int carry = 0 ; for ( int i = 0 ; i < res_size ; i ++ ) { int prod = res [ i ] * x + carry ; res [ i ] = prod % 10 ; carry = prod / 10 ; } while ( carry > 0 ) { res [ res_size ] = carry % 10 ; carry = carry / 10 ; res_size ++ ; } return res_size ; } static void power ( int x , int n ) { if ( n == 0 ) { Console . Write ( "1" ) ; return ; } int [ ] res = new int [ MAX ] ; int res_size = 0 ; int temp = x ; while ( temp != 0 ) { res [ res_size ++ ] = temp % 10 ; temp = temp / 10 ; } for ( int i = 2 ; i <= n ; i ++ ) res_size = multiply ( x , res , res_size ) ; Console . Write ( x + " ^ " + n + " ▁ = ▁ " ) ; for ( int i = res_size - 1 ; i >= 0 ; i -- ) Console . Write ( res [ i ] ) ; } public static void Main ( ) { int exponent = 100 ; int b_ase = 2 ; power ( b_ase , exponent ) ; } }
P | C # program to check if a number is a p - smooth number or not ; function to check if number n is a P - smooth number or not ; prime factorise it by 2 ; if the number is divisible by 2 ; check for all the possible numbers that can divide it ; prime factorize it by i ; stores the maximum if maximum and i , if i divides the number ; if n at the end is a prime number , then it a divisor itself ; Driver program to test above function
using System ; class GFG { static bool check ( int n , int p ) { int maximum = - 1 ; while ( ( n % 2 ) == 0 ) { maximum = Math . Max ( maximum , 2 ) ; n = n / 2 ; } for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i += 2 ) { while ( n % i == 0 ) { maximum = Math . Max ( maximum , i ) ; n = n / i ; } } if ( n > 2 ) maximum = Math . Max ( maximum , n ) ; return ( maximum <= p ) ; } public static void Main ( ) { int n = 24 , p = 7 ; if ( check ( n , p ) ) Console . Write ( " yes " ) ; else Console . Write ( " no " ) ; } }
Program to Change RGB color model to HSV color model | C # program change RGB Color Model to HSV Color Model ; R , G , B values are divided by 255 to change the range from 0. .255 to 0. .1 ; h , s , v = hue , saturation , value double cmax = Math . Max ( r , Math . Max ( g , b ) ) ; maximum of r , g , b double cmin = Math . Min ( r , Math . Min ( g , b ) ) ; minimum of r , g , b double diff = cmax - cmin ; diff of cmax and cmin . ; if cmax and cmax are equal then h = 0 ; if cmax equal r then compute h ; if cmax equal g then compute h ; if cmax equal b then compute h ; if cmax equal zero ; compute v ; Driver Code ; rgb_to_hsv ( 45 , 215 , 0 ) ; rgb_to_hsv ( 31 , 52 , 29 ) ;
using System ; class GFG { static void rgb_to_hsv ( double r , double g , double b ) { r = r / 255.0 ; g = g / 255.0 ; b = b / 255.0 ; double h = - 1 , s = - 1 ; if ( cmax == cmin ) h = 0 ; else if ( cmax == r ) h = ( 60 * ( ( g - b ) / diff ) + 360 ) % 360 ; else if ( cmax == g ) h = ( 60 * ( ( b - r ) / diff ) + 120 ) % 360 ; else if ( cmax == b ) h = ( 60 * ( ( r - g ) / diff ) + 240 ) % 360 ; if ( cmax == 0 ) s = 0 ; else s = ( diff / cmax ) * 100 ; double v = cmax * 100 ; Console . WriteLine ( " ( " + h + " ▁ " + s + " ▁ " + v + " ) " ) ; } public static void Main ( String [ ] args ) { rgb_to_hsv ( 129 , 88 , 47 ) ; } }
Time when minute hand and hour hand coincide | C # code to find the minute at which the minute hand and hour hand coincide ; function to find the minute ; finding the angle between minute hand and the first hour hand ; Driver Code
using System ; class GFG { static void find_time ( int h1 ) { int theta = 30 * h1 ; Console . WriteLine ( " ( " + theta * 2 + " / " + " ▁ 11 ▁ ) minutes " ) ; } public static void Main ( ) { int h1 = 3 ; find_time ( h1 ) ; } }
Sum of Series ( n ^ 2 | C # program to finding the sum of the nth series ; Function that calculate the sum of the nth series ; Using formula of the nth term ; Driver Code
using System ; class GFG { static int sum_series ( int n ) { int nSquare = n * n ; return nSquare * ( nSquare - 1 ) / 4 ; } public static void Main ( ) { int n = 2 ; Console . Write ( sum_series ( n ) ) ; } }
Check if a number is sandwiched between primes | C # Program to check whether a number is sandwiched between two primes or not ; returns true if number n is prime ; 0 and 1 both are non - primes ; finding square root of n ; checking if n has any factor upto square root of n if yes its not prime ; Driver Code
using System ; class GFG { static bool isPrime ( int n ) { if ( n == 0 n == 1 ) return false ; int root = ( int ) Math . Sqrt ( n ) ; for ( int i = 2 ; i <= root ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static bool isSandwitched ( int n ) { return ( isPrime ( n - 1 ) && isPrime ( n + 1 ) ) ; } public static void Main ( ) { int n = 642 ; Console . Write ( n + " ▁ : ▁ " ) ; if ( isSandwitched ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . Write ( " No " ) ; n = 9 ; Console . Write ( n + " ▁ : ▁ " ) ; if ( isSandwitched ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Tomohiko Sakamoto 's Algorithm | A C # program to implement the Tomohiko Sakamoto Algorithm ; function to implement tomohiko sakamoto algorithm ; array with leading number of days values ; if month is less than 3 reduce year by 1 ; Driver Code
using System ; class GFG { public static int day_of_the_week ( int y , int m , int d ) { int [ ] t = { 0 , 3 , 2 , 5 , 0 , 3 , 5 , 1 , 4 , 6 , 2 , 4 } ; if ( m < 3 ) y -= 1 ; return ( y + y / 4 - y / 100 + y / 400 + t [ m - 1 ] + d ) % 7 ; } public static void Main ( ) { int day = 13 , month = 7 , year = 2017 ; Console . WriteLine ( day_of_the_week ( year , month , day ) ) ; } }
Recursive program for prime number | C # Program to find whether a Number is Prime or Not using Recursion ; Returns true if n is prime , else return false . i is current divisor to check . ; Base cases ; Check for next divisor ; Driver code
using System ; class GFG { static bool isPrime ( int n , int i ) { if ( n <= 2 ) return ( n == 2 ) ? true : false ; if ( n % i == 0 ) return false ; if ( i * i > n ) return true ; return isPrime ( n , i + 1 ) ; } static void Main ( ) { int n = 15 ; if ( isPrime ( n , 2 ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Square Free Number | C # Program to print all prime factors ; Returns true if n is a square free number , else returns false . ; If 2 again divides n , then n is not a square free number . ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; Check if i is a prime factor ; If i again divides , then n is not square free ; Driver program
using System ; class GFG { static bool isSquareFree ( int n ) { if ( n % 2 == 0 ) n = n / 2 ; if ( n % 2 == 0 ) return false ; for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { n = n / i ; if ( n % i == 0 ) return false ; } } return true ; } public static void Main ( ) { int n = 10 ; if ( isSquareFree ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Area of a square from diagonal length | C # Program to find the area of square when its diagonal is given . ; Returns area of square from given diagonal ; Driver code
using System ; class GFG { static double findArea ( double d ) { return ( d * d ) / 2 ; } public static void Main ( ) { double d = 10 ; Console . WriteLine ( findArea ( d ) ) ; } }
Sum of series 1 ^ 2 + 3 ^ 2 + 5 ^ 2 + . . . + ( 2 * n | C # Program to find sum of series 1 ^ 2 + 3 ^ 2 + 5 ^ 2 + . . . + ( 2 * n - 1 ) ^ 2. ; Function to find sum of series . ; Driver code
using System ; class GFG { static int sumOfSeries ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ; return sum ; } public static void Main ( ) { int n = 10 ; Console . Write ( sumOfSeries ( n ) ) ; } }
Sum of series 1 ^ 2 + 3 ^ 2 + 5 ^ 2 + . . . + ( 2 * n | C # Program to find sum of series 1 ^ 2 + 3 ^ 2 + 5 ^ 2 + . . . + ( 2 * n - 1 ) ^ 2. ; Function to find sum of series . ; Formula to find sum of series . ; Driver function
using System ; class GFG { static int sumOfSeries ( int n ) { return ( n * ( 2 * n - 1 ) * ( 2 * n + 1 ) ) / 3 ; } public static void Main ( ) { int n = 10 ; Console . Write ( sumOfSeries ( n ) ) ; } }
Program to implement standard error of mean | C # Program to implement standard error of mean . ; Function to find sample mean . ; loop to calculate sum of array elements . ; Function to calculate sample standard deviation . ; Function to calculate sample error . ; Formula to find sample error . ; Driver code
using System ; class GFG { static float mean ( float [ ] arr , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; return sum / n ; } static float SSD ( float [ ] arr , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + ( arr [ i ] - mean ( arr , n ) ) * ( arr [ i ] - mean ( arr , n ) ) ; return ( float ) Math . Sqrt ( sum / ( n - 1 ) ) ; } static float sampleError ( float [ ] arr , int n ) { return SSD ( arr , n ) / ( float ) Math . Sqrt ( n ) ; } public static void Main ( ) { float [ ] arr = { 78.53f , 79.62f , 80.25f , 81.05f , 83.21f , 83.46f } ; int n = arr . Length ; Console . Write ( sampleError ( arr , n ) ) ; } }
Minimum moves to reach target on a infinite line | Set 2 | C # code to find minimum moves to reach target ; Function to find minimum steps to reach target ; Handling negatives by symmetry ; Keep moving while sum is smaller i . e calculating n ; case 1 : d is even ; d is odd ; Driver code ; Function call
using System ; class GFG { static int StepstoReachTarget ( int target ) { target = Math . Abs ( target ) ; int n = ( int ) Math . Ceiling ( ( - 1.0 + ( int ) Math . Sqrt ( 1 + 8.0 * target ) ) / 2 ) ; int sum = n * ( n + 1 ) / 2 ; if ( sum == target ) return n ; int d = sum - target ; if ( ( d & 1 ) == 0 ) return n ; else return n + ( ( n & 1 ) != 0 ? 2 : 1 ) ; } public static void Main ( ) { int target = 5 ; Console . Write ( StepstoReachTarget ( target ) ) ; } }
Sum of series 2 / 3 | C # program to find sum of given series ; Function to find sum of series up - to n terms ; initializing counter by 1 ; variable to calculate result ; while loop until nth term is not reached ; boolean type variable for checking validation ; Driver Code
using System ; class GFG { static double seriesSum ( int n ) { int i = 1 ; double res = 0.0 ; bool sign = true ; while ( n > 0 ) { n -- ; if ( sign ) { sign = ! sign ; res = res + ( double ) ++ i / ++ i ; } else { sign = ! sign ; res = res - ( double ) ++ i / ++ i ; } } return res ; } public static void Main ( ) { int n = 5 ; Console . Write ( seriesSum ( n ) ) ; } }
Number of Symmetric Relations on a Set | C # program to count total symmetric relations on a set of natural numbers . ; function find the square of n ; Base case ; Return 2 ^ ( n ( n + 1 ) / 2 ) ; Driver code
using System ; class GFG { static int countSymmetric ( int n ) { if ( n == 0 ) return 1 ; return 1 << ( ( n * ( n + 1 ) ) / 2 ) ; } public static void Main ( ) { int n = 3 ; Console . WriteLine ( countSymmetric ( n ) ) ; } }
Program for centered nonagonal number | C # Program to find nth centered nonagonal number . ; Function to find nth centered nonagonal number . ; Formula to find nth centered nonagonal number . ; Driver function .
using System ; class GFG { static int centeredNonagonal ( int n ) { return ( 3 * n - 2 ) * ( 3 * n - 1 ) / 2 ; } public static void Main ( ) { int n = 10 ; Console . Write ( centeredNonagonal ( n ) ) ; } }
Program for Mean Absolute Deviation | C # Program to find mean absolute deviation of given array ; Function to find mean of the array elements . ; Calculate sum of all elements . ; Function to find mean absolute deviation of given elements . ; Calculate the sum of absolute deviation about mean . ; Return mean absolute deviation about mean . ; Driver function .
using System ; class GFG { static float Mean ( float [ ] arr , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; return sum / n ; } static float meanAbsDevtion ( float [ ] arr , int n ) { float absSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) absSum = absSum + Math . Abs ( arr [ i ] - Mean ( arr , n ) ) ; return absSum / n ; } public static void Main ( ) { float [ ] arr = { 10 , 15 , 15 , 17 , 18 , 21 } ; int n = arr . Length ; Console . WriteLine ( meanAbsDevtion ( arr , n ) ) ; } }
Find if it is possible to get a ratio from given ranges of costs and quantities | C # program to find if it is possible to get the ratio r ; Returns true if it is possible to get ratio r from given cost and quantity ranges . ; Calculating cost corresponding to value of i ; Driver Code
using System ; class Ratio { static bool isRatioPossible ( int lowCost , int upCost , int lowQuant , int upQuant , int r ) { for ( int i = lowQuant ; i <= upQuant ; i ++ ) { int ans = i * r ; if ( lowCost <= ans && ans <= upCost ) return true ; } return false ; } public static void Main ( ) { int lowCost = 14 , upCost = 30 , lowQuant = 5 , upQuant = 12 , r = 9 ; if ( isRatioPossible ( lowCost , upCost , lowQuant , upQuant , r ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Find N integers with given difference between product and sum | C # code to generate numbers with difference between product and sum is D ; Function to implement calculation ; Driver code
using System ; class GFG { static void findNumbers ( int n , int d ) { for ( int i = 0 ; i < n - 2 ; i ++ ) Console . Write ( "1" + " ▁ " ) ; Console . Write ( "2" + " ▁ " ) ; Console . Write ( n + d ) ; } public static void Main ( ) { int N = 3 , D = 5 ; findNumbers ( N , D ) ; } }
Sum of fourth powers of first n odd natural numbers | C # Program to find the sum of fourth powers of first n odd natural numbers ; calculate the sum of fourth power of first n odd natural numbers ; Driven Program
using System ; class GFG { static long oddNumSum ( int n ) { return ( n * ( 2 * n + 1 ) * ( 24 * n * n * n - 12 * n * n - 14 * n + 7 ) ) / 15 ; } public static void Main ( ) { int n = 4 ; Console . Write ( oddNumSum ( n ) ) ; } }
Trailing number of 0 s in product of two factorials | Java program for count number of trailing zeros in N ! * M ! ; Returns number of zeros in factorial n ; dividing x by powers of 5 and update count ; Returns count of trailing zeros in M ! x N ! ; Driver program
using System ; class GFG { static int trailingZero ( int x ) { int i = 5 , count = 0 ; while ( x > i ) { count = count + x / i ; i = i * 5 ; } return count ; } static int countProductTrailing ( int M , int N ) { return trailingZero ( N ) + trailingZero ( M ) ; } public static void Main ( ) { int N = 67 , M = 98 ; Console . WriteLine ( countProductTrailing ( N , M ) ) ; } }
Trimorphic Number | C # program to check if a number is Trimorphic ; Function to check Trimorphic number ; Store the cube ; Start Comparing digits ; Return false , if any digit of N doesn ' t ▁ match ▁ with ▁ ▁ its ▁ cube ' s digits from last ; Reduce N and cube ; Driver code
using System ; class GFG { static bool isTrimorphic ( int N ) { int cube = N * N * N ; while ( N > 0 ) { if ( N % 10 != cube % 10 ) return false ; N /= 10 ; cube /= 10 ; } return true ; } public static void Main ( ) { int N = 24 ; if ( isTrimorphic ( N ) == true ) Console . Write ( " trimorphic " ) ; else Console . Write ( " not ▁ trimorphic " ) ; } }
Trimorphic Number | C # program to find nth Trimorphic number ; Functions to find nth Trimorphic number ; Comparing the digits ; Return false , if any digit of num doesn ' t ▁ ▁ match ▁ with ▁ its ▁ cube ' s digits from last ; Reduce num and cube ; Check in max int size ; check number is Trimorphic or not ; if counter is equal to the n then return nth number ; Driver code
using System ; class GFG { static int INT_MAX = 2147483647 ; static bool checkTrimorphic ( int num ) { int cube = num * num * num ; while ( num > 0 ) { if ( num % 10 != cube % 10 ) return false ; num /= 10 ; cube /= 10 ; } return true ; } static int nthTrimorphic ( int n ) { int count = 0 ; for ( int i = 0 ; i < INT_MAX ; i ++ ) { if ( checkTrimorphic ( i ) ) count ++ ; if ( count == n ) return i ; } return - 1 ; } static int Main ( ) { int n = 9 ; Console . Write ( nthTrimorphic ( n ) ) ; return 0 ; } }
Find minimum moves to reach target on an infinite line | C # program to find minimum moves to reach target if we can move i steps in i - th move . ; Handling negatives by symmetry ; Keep moving while sum is smaller or difference is odd . ; Driver code
using System ; class GFG { static int reachTarget ( int target ) { target = Math . Abs ( target ) ; int sum = 0 , step = 0 ; while ( sum < target || ( sum - target ) % 2 != 0 ) { step ++ ; sum += step ; } return step ; } public static void Main ( ) { int target = 5 ; Console . WriteLine ( reachTarget ( target ) ) ; } }
Palindromic Selfie Numbers | C # program to find palindromic selfie numbers ; To store all permutations of digits in the number ; int number ; input number ; Function to reverse the digits of a number ; Append it at the beg ; num = num / 10 ; Reduce number until 0 ; Function to check palindromic selfie ; Length of the number required for calculating all permutations of the digits ; Remove the number and its palindrome from the obtained set as this is the LHS of multiplicative equality ; Iterate over all other numbers ; Check for equality x * palin ( x ) = y * palin ( y ) ; flag = true ; Answer found ; If no such number found ; Function to get all possible possible permutations of the digits in num ; Adds the new permutation obtained in the set ; Swap digits to get a different ordering ; Recurse to next pair of digits ; num = swap ( num , l , i ) ; Swap back ; Function that swaps the digits i and j in the num ; Convert int to char array ; Swap the ith and jth character ; Convert back to int and return ; Driver code ; First example , input = 145572 ; Second example , input = 19362 ; Third example , input = 4669
using System ; using System . Collections . Generic ; public class palindrome_selfie { HashSet < int > all_permutes = new HashSet < int > ( ) ; public palindrome_selfie ( int num ) { number = num ; } public int palindrome ( int num ) { int reversednum = 0 ; int d ; while ( num > 0 ) { reversednum = reversednum * 10 + d ; } return reversednum ; } public void palin_selfie ( ) { int l = String . Join ( " " , number ) . Length - 1 ; all_permutes . Remove ( palindrome ( number ) ) ; all_permutes . Remove ( number ) ; foreach ( var number2 in all_permutes ) { if ( number * palindrome ( number ) == number2 * palindrome ( number2 ) ) { Console . WriteLine ( " Palindrome ▁ multiplicative " + " selfie ▁ of ▁ " + number + " ▁ is ▁ : ▁ " + number2 ) ; break ; } } if ( flag == false ) { Console . WriteLine ( " Given ▁ number ▁ has ▁ " + " no ▁ palindrome ▁ selfie . " ) ; } } public void permute ( int num , int l , int r ) { if ( l == r ) all_permutes . Add ( num ) ; else { for ( int i = l ; i <= r ; i ++ ) { num = swap ( num , l , i ) ; permute ( num , l + 1 , r ) ; } } } public int swap ( int num , int i , int j ) { char temp ; char [ ] charArray = String . Join ( " " , num ) . ToCharArray ( ) ; temp = charArray [ i ] ; charArray [ i ] = charArray [ j ] ; charArray [ j ] = temp ; return int . Parse ( String . Join ( " " , charArray ) ) ; } public static void Main ( String [ ] args ) { palindrome_selfie example1 = new palindrome_selfie ( 145572 ) ; example1 . palin_selfie ( ) ; palindrome_selfie example2 = new palindrome_selfie ( 19362 ) ; example2 . palin_selfie ( ) ; palindrome_selfie example3 = new palindrome_selfie ( 4669 ) ; example3 . palin_selfie ( ) ; } }