codeparrot/xlcost-text-to-code huggingface dataset:
Find two distinct prime numbers with given product | C # program to find a distinct prime number pair whose product is equal to given number ; Function to generate all prime numbers less than n ; Initialize all entries of bool array as true . A value in isPrime [ i ] will finally be false if i is Not a prime , else true bool isPrime [ n + 1 ] ; ; If isPrime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Function to print a prime pair with given product ; Generating primes using Sieve ; Traversing all numbers to find first pair ; Driven Code
using System ; class GFG { static void SieveOfEratosthenes ( int n , bool [ ] isPrime ) { isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( int i = 2 ; i <= n ; i ++ ) isPrime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( isPrime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) isPrime [ i ] = false ; } } } static void findPrimePair ( int n ) { int flag = 0 ; bool [ ] isPrime = new bool [ n + 1 ] ; SieveOfEratosthenes ( n , isPrime ) ; for ( int i = 2 ; i < n ; i ++ ) { int x = n / i ; if ( isPrime [ i ] && isPrime [ x ] && x != i && x * i == n ) { Console . Write ( i + " ▁ " + x ) ; flag = 1 ; return ; } } if ( flag == 0 ) Console . Write ( " No ▁ such ▁ pair ▁ found " ) ; } public static void Main ( ) { int n = 39 ; findPrimePair ( n ) ; } }
Program to find the common ratio of three numbers | C # implementation of above approach ; Utility function ; Function to print a : b : c ; To print the given proportion in simplest form . ; Driver code ; Get the ratios ; Get ratio a : b1 ; Get ratio b2 : c ; Find the ratio a : b : c
using System ; class GFG { static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static void solveProportion ( int a , int b1 , int b2 , int c ) { int A = a * b2 ; int B = b1 * b2 ; int C = b1 * c ; int gcd = __gcd ( __gcd ( A , B ) , C ) ; Console . Write ( A / gcd + " : " + B / gcd + " : " + C / gcd ) ; } public static void Main ( ) { int a , b1 , b2 , c ; a = 3 ; b1 = 4 ; b2 = 8 ; c = 9 ; solveProportion ( a , b1 , b2 , c ) ; } }
Number of divisors of a given number N which are divisible by K | C # program to count number of divisors of N which are divisible by K ; Function to count number of divisors of N which are divisible by K ; Variable to store count of divisors ; Traverse from 1 to n ; increase the count if both the conditions are satisfied ; Driver code
using System ; class GFG { static int countDivisors ( int n , int k ) { int count = 0 , i ; for ( i = 1 ; i <= n ; i ++ ) { if ( n % i == 0 && i % k == 0 ) { count ++ ; } } return count ; } public static void Main ( ) { int n = 12 , k = 3 ; Console . WriteLine ( countDivisors ( n , k ) ) ; } }
Calculate volume and surface area of a cone | C # program to calculate Volume and Surface area of cone ; Function to calculate Volume of cone ; Function to calculate Surface area of cone ; Driver Code ; Printing value of volume and surface area
using System ; class GFG { static float pi = 3.14159f ; public static float volume ( float r , float h ) { return ( float ) 1 / 3 * pi * h * r * r ; } public static float surface_area ( float r , float s ) { return pi * r * s + pi * r * r ; } public static void Main ( ) { float radius = 5 ; float slant_height = 13 ; float height = 12 ; Console . Write ( " Volume ▁ Of ▁ Cone ▁ : ▁ " ) ; Console . WriteLine ( volume ( radius , height ) ) ; Console . Write ( " Surface ▁ Area ▁ Of ▁ Cone ▁ : ▁ " ) ; Console . WriteLine ( surface_area ( radius , slant_height ) ) ; } }
Program to find the Nth term of the series 0 , 14 , 40 , 78 , 124 , ... | C # program to find the N - th term of the series 0 , 14 , 40 , 78 , 124 . . . ; calculate sum up to Nth term of series ; return the final sum ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 6 * ( int ) Math . Pow ( n , 2 ) - 4 * n - 2 ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( nthTerm ( N ) ) ; } }
Program to find the Nth term of series 5 , 10 , 17 , 26 , 37 , 50 , 65 , 82 , ... | C # program to find the N - th term of the series : 5 , 10 , 17 , 26 , 37 , 50 , 65 , 82 , ... ; calculate Nth term of series ; return the final sum ; Driver Code
using System ; class GFG { static int nthTerm ( int n ) { return ( int ) Math . Pow ( n , 2 ) + 2 * n + 2 ; } public static void Main ( ) { int N = 4 ; Console . Write ( nthTerm ( N ) ) ; } }
Find nth term of a given recurrence relation | C # program to find nth term of a given recurrence relation ; function to return required value ; Get the answer ; Return the answer ; Driver code ; Get the value of n ; function call to print result
using System ; class GFG { static int sum ( int n ) { int ans = ( n * ( n - 1 ) ) / 2 ; return ans ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( sum ( n ) ) ; } }
Program to find Nth term of the series 3 , 12 , 29 , 54 , 87 , ... | C # program to find N - th term of the series : 3 , 12 , 29 , 54 , 87 , ... ; calculate Nth term of series ; Return Nth term ; Driver code ; declaration of number of terms ; Get the Nth term
using System ; class GFG { static long getNthTerm ( long N ) { return 4 * ( long ) Math . Pow ( N , 2 ) - 3 * N + 2 ; } static public void Main ( ) { long N = 10 ; Console . Write ( getNthTerm ( N ) ) ; } }
Find sum of product of number in given series | C # program to find sum of product of number in given series ; function to calculate ( a ^ b ) % p ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; function to return required answer ; modulo inverse of denominator ; calculating commentator part ; calculating t ! ; accumulating the final answer ; Driver Code ; function call to print required sum
using System ; class GFG { static long MOD = 1000000007 ; static long power ( long x , long y , long p ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } static long sumProd ( long n , long t ) { long dino = power ( t + 1 , MOD - 2 , MOD ) ; long ans = 1 ; for ( long i = n + t + 1 ; i > n ; -- i ) ans = ( ans % MOD * i % MOD ) % MOD ; long tfact = 1 ; for ( int i = 1 ; i <= t ; ++ i ) tfact = ( tfact * i ) % MOD ; ans = ans * dino - tfact + MOD ; return ans % MOD ; } public static void Main ( ) { long n = 3 , t = 2 ; Console . WriteLine ( sumProd ( n , t ) ) ; } }
Find the sum of series 3 , 7 , 13 , 21 , 31. ... | C # program to find sum of n terms of the given series ; Function to calculate sum ; returning the final sum ; Driver Code
using System ; class GFG { static int calculateSum ( int n ) { return ( n * ( ( int ) Math . Pow ( n , 2 ) + 3 * n + 5 ) ) / 3 ; } public static void Main ( ) { int n = 25 ; Console . WriteLine ( calculateSum ( n ) ) ; } }
Minimum Players required to win the game | C # program to find minimum players required to win the game anyhow ; function to calculate ( a ^ b ) % ( 10 ^ 9 + 7 ) . ; function to find the minimum required player ; computing the nenomenator ; computing modulo inverse of denominator ; final result ; Driver code
using System ; class GFG { static long mod = 1000000007 ; static long power ( long a , long b ) { long res = 1 ; while ( b != 0 ) { if ( ( b & 1 ) != 0 ) { res *= a ; res %= mod ; } b /= 2 ; a *= a ; a %= mod ; } return res ; } static long minPlayer ( long n , long k ) { long num = ( ( power ( k , n ) - 1 ) + mod ) % mod ; long den = ( power ( k - 1 , mod - 2 ) + mod ) % mod ; long ans = ( ( ( num * den ) % mod ) * k ) % mod ; return ans ; } public static void Main ( ) { long n = 3 , k = 3 ; Console . WriteLine ( minPlayer ( n , k ) ) ; } }
Sum of Factors of a Number using Prime Factorization | C # Program to find sum of all factors of a given number ; Using SieveOfEratosthenes to find smallest prime factor of all the numbers . For example , if N is 10 , s [ 2 ] = s [ 4 ] = s [ 6 ] = s [ 10 ] = 2 s [ 3 ] = s [ 9 ] = 3 s [ 5 ] = 5 s [ 7 ] = 7 ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries in it as false . ; Initializing smallest factor equal to 2 for all the even numbers ; For odd numbers less then equal to n ; s ( i ) for a prime is the number itself ; For all multiples of current prime number ; i is the smallest prime factor for number " i * j " . ; Function to find sum of all prime factors ; Declaring array to store smallest prime factor of i at i - th index ; Filling values in s [ ] using sieve ; Current prime factor of N ; Power of current prime factor ; N is now N / s [ N ] . If new N als has smallest prime factor as currFactor , increment power ; Update current prime factor as s [ N ] and initializing power of factor as 1. ; Driver code
using System ; class GFG { static void sieveOfEratosthenes ( int N , int [ ] s ) { bool [ ] prime = new bool [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) prime [ i ] = false ; for ( int i = 2 ; i <= N ; i += 2 ) s [ i ] = 2 ; for ( int i = 3 ; i <= N ; i += 2 ) { if ( prime [ i ] == false ) { s [ i ] = i ; for ( int j = i ; j * i <= N ; j += 2 ) { if ( prime [ i * j ] == false ) { prime [ i * j ] = true ; s [ i * j ] = i ; } } } } } static int findSum ( int N ) { int [ ] s = new int [ N + 1 ] ; int ans = 1 ; sieveOfEratosthenes ( N , s ) ; int currFactor = s [ N ] ; int power = 1 ; while ( N > 1 ) { N /= s [ N ] ; if ( currFactor == s [ N ] ) { power ++ ; continue ; } int sum = 0 ; for ( int i = 0 ; i <= power ; i ++ ) sum += ( int ) Math . Pow ( currFactor , i ) ; ans *= sum ; currFactor = s [ N ] ; power = 1 ; } return ans ; } public static void Main ( ) { int n = 12 ; Console . Write ( " Sum ▁ of ▁ the ▁ factors ▁ is ▁ : ▁ " ) ; Console . WriteLine ( findSum ( n ) ) ; } }
Find Multiples of 2 or 3 or 5 less than or equal to N | C # program to count number of multiples of 2 or 3 or 5 less than or equal to N ; Bit count function ; Function to count number of multiples of 2 or 3 or 5 less than or equal to N ; As we have to check divisibility by three numbers , So we can implement bit masking ; we check whether jth bit is set or not , if jth bit is set , simply multiply to prod ; check for set bit ; check multiple of product ; Driver code
using System ; public class GFG { static int count_setbits ( int N ) { int cnt = 0 ; while ( N > 0 ) { cnt += ( N & 1 ) ; N = N >> 1 ; } return cnt ; } static int countMultiples ( int n ) { int [ ] multiple = { 2 , 3 , 5 } ; int count = 0 , mask = ( int ) Math . Pow ( 2 , 3 ) ; for ( int i = 1 ; i < mask ; i ++ ) { int prod = 1 ; for ( int j = 0 ; j < 3 ; j ++ ) { if ( ( i & 1 << j ) > 0 ) prod = prod * multiple [ j ] ; } if ( count_setbits ( i ) % 2 == 1 ) count = count + n / prod ; else count = count - n / prod ; } return count ; } static public void Main ( ) { int n = 10 ; Console . WriteLine ( countMultiples ( n ) ) ; } }
Minimum value of N such that xor from 1 to N is equal to K | C # implementation of above approach ; Function to find the value of N ; variable to store the result ; handling case for '0' ; handling case for '1' ; when number is completely divided by 4 then minimum ' x ' will be ' k ' ; when number divided by 4 gives 3 as remainder then minimum ' x ' will be ' k - 1' ; else it is not possible to get k for any value of x ; Driver code ; let the given number be 7
using System ; class GFG { static int findN ( int k ) { int ans ; if ( k == 0 ) ans = 3 ; if ( k == 1 ) ans = 1 ; else if ( k % 4 == 0 ) ans = k ; else if ( k % 4 == 3 ) ans = k - 1 ; else ans = - 1 ; return ans ; } public static void Main ( ) { int k = 7 ; int res = findN ( k ) ; if ( res == - 1 ) Console . WriteLine ( " Not ▁ possible " ) ; else Console . WriteLine ( res ) ; } }
Permutations to arrange N persons around a circular table | C # code to demonstrate Circular Permutation ; Function to find no . of permutations ; Driver Code
using System ; public class GFG { static int Circular ( int n ) { int Result = 1 ; while ( n > 0 ) { Result = Result * n ; n -- ; } return Result ; } public static void Main ( ) { int n = 4 ; Console . Write ( Circular ( n - 1 ) ) ; } }
Minimum time required to complete a work by N persons together | C # implementation of above approach ; Function to calculate the time ; Driver Code
using System ; class GFG { static double calTime ( double [ ] arr , int n ) { double work = 0 ; for ( int i = 0 ; i < n ; i ++ ) work += 1 / arr [ i ] ; return Math . Round ( 1 / work , 5 ) ; } public static void Main ( ) { double [ ] arr = { 6.0 , 3.0 , 4.0 } ; int n = arr . Length ; Console . Write ( calTime ( arr , n ) + " ▁ Hours " ) ; } }
Find the largest twins in given range | C # program to find the largest twin in given range ; Function to find twins ; Create a boolean array " prime [ 0 . . high ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; Look for the smallest twin ; If p is not marked , then it is a prime ; Update all multiples of p ; Now print the largest twin in range ; Driver Code
class GFG { static void printTwins ( int low , int high ) { bool [ ] prime = new bool [ high + 1 ] ; bool twin = false ; for ( int i = 0 ; i < high + 1 ; i ++ ) prime [ i ] = true ; prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p <= System . Math . Floor ( System . Math . Sqrt ( high ) ) + 1 ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= high ; i += p ) prime [ i ] = false ; } } for ( int i = high ; i >= low ; i -- ) { if ( prime [ i ] && ( i - 2 >= low && prime [ i - 2 ] == true ) ) { System . Console . WriteLine ( " Largest ▁ twins ▁ in ▁ given ▁ range : ▁ ( " + ( i - 2 ) + " , ▁ " + ( i ) + " ) " ) ; twin = true ; break ; } } if ( twin == false ) System . Console . WriteLine ( " No ▁ such ▁ pair ▁ exists " ) ; } public static void Main ( ) { printTwins ( 10 , 100 ) ; } }
Complement of a number with any base b | C # program to find complement of a number with any base b ; Function to find ( b - 1 ) 's complement ; Calculate number of digits in the given number ; Largest digit in the number system with base b ; Largest number in the number system with base b ; return Complement ; Function to find b 's complement ; b ' s ▁ complement ▁ = ▁ ( b - 1 ) ' s complement + 1 ; Driver code
class GFG { static int prevComplement ( int n , int b ) { int maxDigit , maxNum = 0 , digits = 0 , num = n ; while ( n != 0 ) { digits ++ ; n = n / 10 ; } maxDigit = b - 1 ; while ( ( digits -- ) > 0 ) { maxNum = maxNum * 10 + maxDigit ; } return maxNum - num ; } static int complement ( int n , int b ) { return prevComplement ( n , b ) + 1 ; } public static void Main ( ) { System . Console . WriteLine ( prevComplement ( 25 , 7 ) ) ; System . Console . WriteLine ( complement ( 25 , 7 ) ) ; } }
Minimum positive integer value possible of X for given A and B in X = P * A + Q * B | CSHARP Program to find minimum value of X in equation X = P * A + Q * B ; function to get gcd of a and b ; Driver Code
using System ; class GFG { public static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static public void Main ( ) { int a = 2 ; int b = 4 ; Console . WriteLine ( gcd ( a , b ) ) ; } }
Count elements in the given range which have maximum number of divisors | C # implementation of above approach ; Function to count the elements with maximum number of divisors ; to store number of divisors ; initialise with zero ; to store the maximum number of divisors ; to store required answer ; Find the first divisible number ; Count number of divisors ; Find number of elements with maximum number of divisors ; Driver code
using System ; class GFG { static int MaximumDivisors ( int X , int Y ) { int [ ] arr = new int [ Y - X + 1 ] ; for ( int i = 0 ; i < arr . Length ; i ++ ) arr [ i ] = 0 ; int mx = 0 ; int cnt = 0 ; for ( int i = 1 ; i * i <= Y ; i ++ ) { int sq = i * i ; int first_divisible ; if ( ( X / i ) * i >= X ) first_divisible = ( X / i ) * i ; else first_divisible = ( X / i + 1 ) * i ; for ( int j = first_divisible ; j <= Y ; j += i ) { if ( j < sq ) continue ; else if ( j == sq ) arr [ j - X ] ++ ; else arr [ j - X ] += 2 ; } } for ( int i = X ; i <= Y ; i ++ ) { if ( arr [ i - X ] > mx ) { cnt = 1 ; mx = arr [ i - X ] ; } else if ( arr [ i - X ] == mx ) cnt ++ ; } return cnt ; } public static void Main ( ) { int X = 1 , Y = 10 ; Console . Write ( MaximumDivisors ( X , Y ) ) ; } }
Find First element in AP which is multiple of given prime | C # Program to Find First element in AP which is multiple of given prime ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; function to find nearest element in common ; base conditions ; Driver code ; module both A and D ; function call
using System ; class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } static int NearestElement ( int A , int D , int P ) { if ( A == 0 ) return 0 ; else if ( D == 0 ) return - 1 ; else { int X = power ( D , P - 2 , P ) ; return ( X * ( P - A ) ) % P ; } } public static void Main ( ) { int A = 4 , D = 9 , P = 11 ; A %= P ; D %= P ; Console . WriteLine ( NearestElement ( A , D , P ) ) ; } }
Cunningham chain | C # Program to print the series of first kind ; Function to print Cunningham chain of the first kind ; Iterate till all elements are printed ; check prime or not ; Driver Code
using System ; class GFG { static void print ( int p0 ) { int p1 , i = 0 , x , flag , k ; while ( true ) { flag = 1 ; x = ( int ) ( Math . Pow ( 2 , i ) ) ; p1 = x * p0 + ( x - 1 ) ; for ( k = 2 ; k < p1 ; k ++ ) { if ( p1 % k == 0 ) { flag = 0 ; break ; } } if ( flag == 0 ) break ; Console . Write ( " ▁ " + p1 ) ; i ++ ; } } public static void Main ( ) { int p0 = 2 ; print ( p0 ) ; } }
Count pairs with Bitwise AND as ODD number | C # program to count pairs with AND giving a odd number ; Function to count number of odd pairs ; variable for counting odd pairs ; find all pairs ; find AND operation check odd or even ; return number of odd pair ; Driver Code ; calling function findOddPair and print number of odd pair
using System ; class GFG { static int findOddPair ( int [ ] A , int N ) { int i , j ; int oddPair = 0 ; for ( i = 0 ; i < N ; i ++ ) { for ( j = i + 1 ; j < N ; j ++ ) { if ( ( A [ i ] & A [ j ] ) % 2 != 0 ) oddPair ++ ; } } return oddPair ; } public static void Main ( ) { int [ ] a = { 5 , 1 , 3 , 2 } ; int n = a . Length ; Console . WriteLine ( findOddPair ( a , n ) ) ; } }
Sudo Placement [ 1.7 ] | Greatest Digital Root | C # program to print the digital roots of a number ; Function to return dig - sum ; Function to print the Digital Roots ; store the largest digital roots ; Iterate till sqrt ( n ) ; if i is a factor ; get the digit sum of both factors i and n / i ; if digit sum is greater then previous maximum ; if digit sum is greater then previous maximum ; if digit sum is same as then previous maximum , then check for larger divisor ; if digit sum is same as then previous maximum , then check for larger divisor ; Print the digital roots ; Driver Code ; Function call to print digital roots
using System ; class GFG { static int summ ( int n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } static void printDigitalRoot ( int n ) { int maxi = 1 ; int dig = 1 ; for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { int d1 = summ ( n / i ) ; int d2 = summ ( i ) ; if ( d1 > maxi ) { dig = n / i ; maxi = d1 ; } if ( d2 > maxi ) { dig = i ; maxi = d2 ; } if ( d1 == maxi ) { if ( dig < ( n / i ) ) { dig = n / i ; maxi = d1 ; } } if ( d2 == maxi ) { if ( dig < i ) { dig = i ; maxi = d2 ; } } } } Console . WriteLine ( dig + " ▁ " + maxi ) ; } public static void Main ( ) { int n = 10 ; printDigitalRoot ( n ) ; } }
Sum of all elements up to Nth row in a Pascal triangle | C # program to find sum of all elements upto nth row in Pascal triangle . ; Function to find sum of all elements upto nth row . ; Initialize sum with 0 ; Calculate 2 ^ n ; Driver code
using System ; public class GFG { static long calculateSum ( int n ) { long sum = 0 ; sum = 1 << n ; return ( sum - 1 ) ; } static public void Main ( ) { int n = 10 ; Console . WriteLine ( " Sum ▁ of ▁ all ▁ elements : " + calculateSum ( n ) ) ; } }
Divide two integers without using multiplication , division and mod operator | Set2 | C # program for above approach ; Returns the quotient of dividend / divisor . ; Calculate sign of divisor i . e . , sign will be negative only if either one of them is negative otherwise it will be positive ; Remove signs of dividend and divisor ; Zero division Exception . ; Using Formula derived above . ; Driver code
using System ; class GFG { static void Divide ( int a , int b ) { long dividend = ( long ) a ; long divisor = ( long ) b ; long sign = ( dividend < 0 ) ^ ( divisor < 0 ) ? - 1 : 1 ; dividend = Math . Abs ( dividend ) ; divisor = Math . Abs ( divisor ) ; if ( divisor == 0 ) { Console . WriteLine ( " Cannot ▁ Divide ▁ by ▁ 0" ) ; return ; } if ( dividend == 0 ) { Console . WriteLine ( a + " ▁ / ▁ " + b + " ▁ is ▁ equal ▁ to ▁ : ▁ " + 0 ) ; return ; } if ( divisor == 1 ) { Console . WriteLine ( a + " ▁ / ▁ " + b + " ▁ is ▁ equal ▁ to ▁ : ▁ " + sign * dividend ) ; return ; } Console . WriteLine ( a + " ▁ / ▁ " + b + " ▁ is ▁ equal ▁ to ▁ : ▁ " + Math . Floor ( sign * ( Math . Exp ( Math . Log ( dividend ) - Math . Log ( divisor ) ) ) ) ) ; } public static void Main ( ) { int a = 10 , b = 5 ; Divide ( a , b ) ; a = 49 ; b = - 7 ; Divide ( a , b ) ; } }
Check if the n | C # Program to check if the nth is odd or even in a sequence where each term is sum of previous two term ; Return if the nth term is even or odd . ; If a is even ; If b is even ; If b is odd ; If a is odd ; If b is odd ; If b is eve ; Driven Program
class GFG { static bool findNature ( int a , int b , int n ) { if ( n == 0 ) return ( a & 1 ) == 1 ? true : false ; if ( n == 1 ) return ( b & 1 ) == 1 ? true : false ; if ( ( a & 1 ) == 0 ) { if ( ( b & 1 ) == 0 ) return false ; else return ( n % 3 != 0 ) ; } else { if ( ( b & 1 ) == 0 ) return ( ( n - 1 ) % 3 != 0 ) ; else return ( ( n + 1 ) % 3 != 0 ) ; } } static void Main ( ) { int a = 2 , b = 4 ; int n = 3 ; if ( findNature ( a , b , n ) ) System . Console . WriteLine ( " Odd " ) ; else System . Console . WriteLine ( " Even " ) ; } }
Check if mirror image of a number is same if displayed in seven segment display | C # Program to check if mirror image of a number is same if displayed in seven segment display ; Return " Yes " , if the mirror image of number is same as the given number Else return " No " ; Checking if the number contain only 0 , 1 , 8. ; Checking if the number is palindrome or not . ; If corresponding index is not equal . ; Driver Code
using System ; class GFG { static string checkEqual ( string S ) { for ( int i = 0 ; i < S . Length ; i ++ ) { if ( S [ i ] != '1' && S [ i ] != '0' && S [ i ] != '8' ) { return " No " ; } } int start = 0 , end = S . Length - 1 ; while ( start < end ) { if ( S [ start ] != S [ end ] ) { return " No " ; } start ++ ; end -- ; } return " Yes " ; } public static void Main ( ) { string S = "101" ; Console . WriteLine ( checkEqual ( S ) ) ; } }
Check whether a given number is Polydivisible or Not | C # program to check whether a number is polydivisible or not ; function to check polydivisible number ; digit extraction of input number ; store the digits in an array ; n contains first i digits ; n should be divisible by i ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void check_polydivisible ( int n ) { int N = n ; List < int > digit = new List < int > ( ) ; while ( n > 0 ) { digit . Add ( ( int ) n % 10 ) ; n /= 10 ; } digit . Reverse ( ) ; bool flag = true ; n = digit [ 0 ] ; for ( int i = 1 ; i < digit . Count ; i ++ ) { n = n * 10 + digit [ i ] ; if ( n % ( i + 1 ) != 0 ) { flag = false ; break ; } } if ( flag ) Console . WriteLine ( N + " ▁ is ▁ Polydivisible ▁ number . " ) ; else Console . WriteLine ( N + " ▁ is ▁ Not ▁ Polydivisible ▁ number . " ) ; } public static void Main ( String [ ] args ) { int n = 345654 ; check_polydivisible ( n ) ; } }