codeparrot/xlcost-text-to-code huggingface dataset:
Midy 's theorem | C # implementation as a proof of the Midy 's theorem ; Returns repeating sequence of a fraction . If repeating sequence doesn 't exits, then returns -1 ; Create a map to store already seen remainders remainder is used as key and its position in result is stored as value . Note that we need position for cases like 1 / 6. In this case , the recurring sequence doesn 't start from first  remainder.  ; Find first remainder ; Keep finding remainder until either remainder becomes 0 or repeats ; Store this remainder ; Multiply remainder with 10 ; Append rem / denr to result ; Update remainder ; Checks whether a number is prime or not ; If all conditions are met , it proves Midy 's theorem ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static String fractionToDecimal ( int numerator , int denominator ) { String res = " " ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; int rem = numerator % denominator ; while ( ( rem != 0 ) && ! mp . ContainsKey ( rem ) ) { mp [ rem ] = res . Length ; rem = rem * 10 ; int res_part = rem / denominator ; res += res_part + " " ; rem = rem % denominator ; } return ( rem == 0 ) ? " - 1" : res . Substring ( mp [ rem ] ) ; } static bool isPrime ( int n ) { for ( int i = 2 ; i <= n / 2 ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static void Midys ( String str , int n ) { int l = str . Length ; int part1 = 0 , part2 = 0 ; if ( ! isPrime ( n ) ) { Console . Write ( " Denominator ▁ is ▁ not ▁ prime , ▁ " + " thus ▁ Midy ' s ▁ theorem ▁ is ▁ not ▁ " + " applicable " ) ; } else if ( l % 2 == 0 ) { for ( int i = 0 ; i < l / 2 ; i ++ ) { part1 = part1 * 10 + ( str [ i ] - '0' ) ; part2 = part2 * 10 + ( str [ l / 2 + i ] - '0' ) ; } Console . WriteLine ( part1 + " ▁ + ▁ " + part2 + " ▁ = ▁ " + ( part1 + part2 ) ) ; Console . Write ( " Midy ' s ▁ theorem ▁ holds ! " ) ; } else { Console . Write ( " The ▁ repeating ▁ decimal ▁ is ▁ " + " of ▁ odd ▁ length ▁ thus ▁ Midy ' s ▁ " + " theorem ▁ is ▁ not ▁ applicable " ) ; } } public static void Main ( string [ ] args ) { int numr = 2 , denr = 11 ; string res = fractionToDecimal ( numr , denr ) ; if ( res == " - 1" ) Console . Write ( " The ▁ fraction ▁ does ▁ not ▁ " + " have ▁ repeating ▁ decimal " ) ; else { Console . WriteLine ( " Repeating ▁ decimal ▁ = ▁ " + res ) ; Midys ( res , denr ) ; } } }
Sum of fourth power of first n even natural numbers | C # Program to find the sum of fourth powers of first n even natural numbers ; calculate the sum of fourth power of first n even natural numbers ; made even number ; Driven Program
using System ; class GFG { static long evenPowerSum ( int n ) { long sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int j = 2 * i ; sum = sum + ( j * j * j * j ) ; } return sum ; } public static void Main ( ) { int n = 5 ; Console . Write ( evenPowerSum ( n ) ) ; } }
Sum of fourth power of first n even natural numbers | C # Program to find the sum of fourth powers of first n even natural numbers ; calculate the sum of fourth power of first n even natural numbers ; Driven Program
using System ; class GFG { static long evenPowerSum ( int n ) { return ( 8 * n * ( n + 1 ) * ( 2 * n + 1 ) * ( 3 * n * n + 3 * n - 1 ) ) / 15 ; } public static void Main ( ) { int n = 4 ; Console . Write ( evenPowerSum ( n ) ) ; } }
Balanced Prime | C # Program to find Nth Balanced Prime ; Return the Nth balanced prime . ; Sieve of Eratosthenes ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; storing all primes ; Finding the Nth balanced Prime ; Driven Program
using System ; using System . Collections . Generic ; public class GFG { static int MAX = 501 ; public static int balancedprime ( int n ) { bool [ ] prime = new bool [ MAX + 1 ] ; for ( int k = 0 ; k < MAX + 1 ; k ++ ) prime [ k ] = true ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } List < int > v = new List < int > ( ) ; for ( int p = 3 ; p <= MAX ; p += 2 ) if ( prime [ p ] ) v . Add ( p ) ; int c = 0 ; for ( int i = 1 ; i < v . Count - 1 ; i ++ ) { if ( ( int ) v [ i ] == ( int ) ( v [ i + 1 ] + v [ i - 1 ] ) / 2 ) c ++ ; if ( c == n ) return ( int ) v [ i ] ; } return 1 ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( balancedprime ( n ) ) ; } }
Smallest integer which has n factors or more | C # program to print the smallest integer with n factors or more ; array to store prime factors ; function to generate all prime factorsof numbers from 1 to 10 ^ 6 ; Initializes all the positions with their value . ; Initializes all multiples of 2 with 2 ; A modified version of Sieve of Eratosthenes to store the smallest prime factor that divides every number . ; check if it has no prime factor . ; Initializes of j starting from i * i ; if it has no prime factor before , then stores the smallest prime divisor ; function to calculate number of factors ; stores the smallest prime number that divides n ; stores the count of number of times a prime number divides n . ; reduces to the next number after prime factorization of n ; false when prime factorization is done ; if the same prime number is dividing n , then we increase the count ; if its a new prime factor that is factorizing n , then we again set c = 1 and change dup to the new prime factor , and apply the formula explained above . ; prime factorizes a number ; for the last prime factor ; function to find the smallest integer with n factors or more . ; check if no of factors is more than n or not ; Driver Code ; generate prime factors of number upto 10 ^ 6
using System ; class GfG { private static int MAX = 1000001 ; private static int [ ] factor = new int [ MAX ] ; public static void generatePrimeFactors ( ) { factor [ 1 ] = 1 ; for ( int i = 2 ; i < MAX ; i ++ ) factor [ i ] = i ; for ( int i = 4 ; i < MAX ; i += 2 ) factor [ i ] = 2 ; for ( int i = 3 ; i * i < MAX ; i ++ ) { if ( factor [ i ] == i ) { for ( int j = i * i ; j < MAX ; j += i ) { if ( factor [ j ] == j ) factor [ j ] = i ; } } } } public static int calculateNoOFactors ( int n ) { if ( n == 1 ) return 1 ; int ans = 1 ; int dup = factor [ n ] ; int c = 1 ; int j = n / factor [ n ] ; while ( j != 1 ) { if ( factor [ j ] == dup ) c += 1 ; else { dup = factor [ j ] ; ans = ans * ( c + 1 ) ; c = 1 ; } j = j / factor [ j ] ; } ans = ans * ( c + 1 ) ; return ans ; } public static int smallest ( int n ) { for ( int i = 1 ; ; i ++ ) if ( calculateNoOFactors ( i ) >= n ) return i ; } public static void Main ( ) { generatePrimeFactors ( ) ; int n = 4 ; Console . Write ( smallest ( n ) ) ; } }
Sum of squares of first n natural numbers | C # Program to find sum of square of first n natural numbers ; Return the sum of square of first n natural numbers ; Iterate i from 1 and n finding square of i and add to sum . ; Driven Program
using System ; class GFG { static int squaresum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += ( i * i ) ; return sum ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( squaresum ( n ) ) ; } }
Break a number such that sum of maximum divisors of all parts is minimum | C # Code for Break a number such that sum of maximum divisors of all parts is minimum ; Function to check if a number is prime or not . ; If n is an even number ( we can write it as sum of two primes ) ; If n is odd and n - 2 is prime . ; If n is odd , n - 3 must be even . ; Driver program
using System ; class GFG { static bool isPrime ( int n ) { int i = 2 ; while ( i * i <= n ) { if ( n % i == 0 ) return false ; i ++ ; } return true ; } static int minimumSum ( int n ) { if ( isPrime ( n ) ) return 1 ; if ( n % 2 == 0 ) return 2 ; if ( isPrime ( n - 2 ) ) return 2 ; return 3 ; } public static void Main ( ) { int n = 27 ; Console . WriteLine ( minimumSum ( n ) ) ; } }
Find first and last digits of a number | C # Program to find first and last digits of a number ; Find the first digit ; Remove last digit from number till only one digit is left ; return the first digit ; Find the last digit ; return the last digit ; driver function
using System ; public class GfG { public static int firstDigit ( int n ) { while ( n >= 10 ) n /= 10 ; return n ; } public static int lastDigit ( int n ) { return ( n % 10 ) ; } public static void Main ( ) { int n = 98562 ; Console . WriteLine ( firstDigit ( n ) + " ▁ " + lastDigit ( n ) ) ; } }
Find first and last digits of a number | C # program to find first and last digits of a number ; Find the first digit ; Find total number of digits - 1 ; Find first digit ; Return first digit ; Find the last digit ; return the last digit ; Driver program
using System ; class GFG { static int firstDigit ( int n ) { int digits = ( int ) ( Math . Log10 ( n ) ) ; n = ( int ) ( n / ( int ) ( Math . Pow ( 10 , digits ) ) ) ; return n ; } static int lastDigit ( int n ) { return ( n % 10 ) ; } public static void Main ( ) { int n = 98562 ; Console . WriteLine ( firstDigit ( n ) + " ▁ " + lastDigit ( n ) ) ; } }
Express an odd number as sum of prime numbers | C # program to express N as sum of at - most three prime numbers . ; Function to check if a number is prime or not . ; Prints at most three prime numbers whose sum is n . ; if ( isPrime ( n ) ) CASE - I ; else if ( isPrime ( n - 2 ) ) CASE - II ; else CASE - III ; Driver code
using System ; class GFG { public static bool isPrime ( int x ) { if ( x == 0 x == 1 ) return false ; for ( int i = 2 ; i * i <= x ; ++ i ) if ( x % i == 0 ) return false ; return true ; } public static void findPrimes ( int n ) { Console . WriteLine ( n ) ; Console . Write ( 2 + " ▁ " + ( n - 2 ) ) ; { Console . Write ( 3 + " ▁ " ) ; n = n - 3 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPrime ( i ) && isPrime ( n - i ) ) { Console . WriteLine ( i + " ▁ " + ( n - i ) ) ; break ; } } } } public static void Main ( ) { int n = 27 ; findPrimes ( n ) ; } }
AKS Primality Test | C # code to check if number is prime . This program demonstrates concept behind AKS algorithm and doesn 't implement the actual algorithm (This works only till n = 64) ; array used to store coefficients . ; function to calculate the coefficients of ( x - 1 ) ^ n - ( x ^ n - 1 ) with the help of Pascal 's triangle . ; function to check whether the number is prime or not ; Calculating all the coefficients by the function coef and storing all the coefficients in c array . ; subtracting c [ n ] and adding c [ 0 ] by 1 as ( x - 1 ) ^ n - ( x ^ n - 1 ) , here we are subtracting c [ n ] by 1 and adding 1 in expression . ; checking all the coefficients whether they are divisible by n or not . if n is not prime , then loop breaks and ( i > 0 ) . ; Return true if all coefficients are divisible by n . ; Driver code
using System ; class GFG { static long [ ] c = new long [ 100 ] ; static void coef ( int n ) { c [ 0 ] = 1 ; for ( int i = 0 ; i < n ; c [ 0 ] = - c [ 0 ] , i ++ ) { c [ 1 + i ] = 1 ; for ( int j = i ; j > 0 ; j -- ) c [ j ] = c [ j - 1 ] - c [ j ] ; } } static bool isPrime ( int n ) { coef ( n ) ; c [ 0 ] ++ ; c [ n ] -- ; int i = n ; while ( ( i -- ) > 0 && c [ i ] % n == 0 ) ; return i < 0 ; } public static void Main ( ) { int n = 37 ; if ( isPrime ( n ) ) Console . WriteLine ( " Prime " ) ; else Console . WriteLine ( " Not ▁ Prime " ) ; } }
Motzkin number | C # Program to find Nth Motzkin Number . ; Return the nth Motzkin Number . ; Base Case ; Recursive step ; driver code
using System ; class GFG { public static int motzkin ( int n ) { if ( n == 0 n == 1 ) return 1 ; return ( ( 2 * n + 1 ) * motzkin ( n - 1 ) + ( 3 * n - 3 ) * motzkin ( n - 2 ) ) / ( n + 2 ) ; } public static void Main ( ) { int n = 8 ; Console . WriteLine ( motzkin ( n ) ) ; } }
Sum of the series 0.6 , 0.06 , 0.006 , 0.0006 , ... to n terms | C # program to find sum of 0.6 , 0.06 , 0.006 , 0.0006 , ... to n terms ; function which return the the sum of series ; Driver code
using System ; class GFG { static double sumOfSeries ( int n ) { return ( 0.666 ) * ( 1 - 1 / Math . Pow ( 10 , n ) ) ; } public static void Main ( ) { int n = 2 ; Console . WriteLine ( sumOfSeries ( n ) ) ; } }
Narcissistic number | C # program for checking of Narcissistic number ; function to count digits ; Returns true if n is Narcissistic number ; count the number of digits ; calculates the sum of digits raised to power ; Driver code
using System ; class narcissistic { int countDigit ( int n ) { if ( n == 0 ) return 0 ; return 1 + countDigit ( n / 10 ) ; } bool check ( int n ) { int l = countDigit ( n ) ; int dup = n ; int sum = 0 ; while ( dup > 0 ) { sum += ( int ) Math . Pow ( dup % 10 , l ) ; dup /= 10 ; } return ( n == sum ) ; } public static void Main ( ) { narcissistic obj = new narcissistic ( ) ; int n = 1634 ; if ( obj . check ( n ) ) Console . WriteLine ( " yes " ) ; else Console . WriteLine ( " no " ) ; } }
Sum of squares of first n natural numbers | C # program to calculate 1 ^ 2 + 2 ^ 2 + 3 ^ 2 + ... ; Function to calculate sum ; Driver code
using System ; class GFG { public static int summation ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += ( i * i ) ; return sum ; } public static void Main ( ) { int n = 2 ; Console . WriteLine ( summation ( n ) ) ; } }
Leyland Number | C # program to print first N Leyland Numbers . ; Print first n Leyland Number . ; Outer loop for x from 2 to n . ; Inner loop for y from 2 to x . ; Calculating x ^ y + y ^ x ; Sorting the all Leyland Number . ; Printing first n Leyland number . ; Driver Code
using System ; using System . Collections ; class GFG { public static void leyland ( int n ) { ArrayList ans = new ArrayList ( ) ; for ( int x = 2 ; x <= n ; x ++ ) { for ( int y = 2 ; y <= x ; y ++ ) { int temp = ( int ) Math . Pow ( x , y ) + ( int ) Math . Pow ( y , x ) ; ans . Add ( temp ) ; } } ans . Sort ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( ans [ i ] + " ▁ " ) ; } } public static void Main ( ) { int n = 6 ; leyland ( n ) ; } }
Nicomachusâ €™ s Theorem ( Sum of k | C # code to find sum of k - th group of positive odd integers . ; Return the sum of k - th group of positive odd integers . ; Finding first element of kth group . ; Finding the sum . ; Driver program to test above methods
using System ; class GFG { public static int kthgroupsum ( int k ) { int cur = ( k * ( k - 1 ) ) + 1 ; int sum = 0 ; while ( k -- > 0 ) { sum += cur ; cur += 2 ; } return sum ; } public static void Main ( ) { int k = 3 ; Console . WriteLine ( kthgroupsum ( k ) ) ; } }
n | C # program to find n - th term of the series 2 , 12 , 36 , 80 , 150 , . . ; Returns n - th term of the series 2 , 12 , 36 , 80 , 150 ; Driver code
using System ; class GFG { public static int nthTerm ( int n ) { return ( n * n ) + ( n * n * n ) ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( nthTerm ( n ) ) ; } }
Sum of the series 1 , 3 , 6 , 10. . . ( Triangular Numbers ) | C # program to find sum series 1 , 3 , 6 , 10 , 15 , 21. . . and then find its sum ; Function to find the sum of series ; Driver code
using System ; class GFG { static int seriesSum ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( seriesSum ( n ) ) ; } }
Calculate speed , distance and time | C # Program to calculate speed distance and time ; Function to calculate speed ; Function to calculate distance traveled ; Function to calculate time taken ; Driver code ; Calling function cal_speed ( ) ; Calling function cal_dis ( ) ; Calling function cal_time ( )
using System ; class GFG { static double cal_speed ( double dist , double time ) { Console . WriteLine ( " ▁ Distance ( km ) ▁ : ▁ " + dist ) ; Console . WriteLine ( " ▁ Time ( hr ) ▁ : ▁ " + time ) ; return dist / time ; } static double cal_dis ( double speed , double time ) { Console . WriteLine ( " ▁ Time ( hr ) ▁ : ▁ " + time ) ; Console . WriteLine ( " ▁ Speed ( km ▁ / ▁ hr ) ▁ : ▁ " + speed ) ; return speed * time ; } static double cal_time ( double dist , double speed ) { Console . WriteLine ( " ▁ Distance ( km ) ▁ : ▁ " + dist ) ; Console . WriteLine ( " ▁ Speed ( km ▁ / ▁ hr ) ▁ : ▁ " + speed ) ; return speed * dist ; } public static void Main ( ) { Console . WriteLine ( " ▁ The ▁ calculated ▁ Speed ( km ▁ / ▁ hr ) ▁ is ▁ : ▁ " + cal_speed ( 45.9 , 2.0 ) ) ; Console . WriteLine ( " ▁ The ▁ calculated ▁ Distance ( km ) ▁ : ▁ " + cal_dis ( 62.9 , 2.5 ) ) ; Console . WriteLine ( " ▁ The ▁ calculated ▁ Time ( hr ) ▁ : ▁ " + cal_time ( 48.0 , 4.5 ) ) ; } }
Find n | C # program to find n - th term of series 1 , 3 , 6 , 10 , 15 , 21. . . ; Function to find the nth term of series ; Loop to add numbers ; Driver code
using System ; class GFG { static int term ( int n ) { int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) ans += i ; return ans ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( term ( n ) ) ; } }
Find the average of first N natural numbers | C # Program to find the Average of first n natural numbers ; Return the average of first n natural numbers ; Driven Program
using System ; class GFG { static float avgOfFirstN ( int n ) { return ( float ) ( 1 + n ) / 2 ; } public static void Main ( ) { int n = 20 ; Console . WriteLine ( avgOfFirstN ( n ) ) ; } }
Find the sum of the series 1 + 11 + 111 + 1111 + ... . . upto n terms | C # program to find the sum of the series 1 + 11 + 111 + 1111 + ... . ; Function for finding summation ; Driver Code
using System ; class GFG { static int summation ( int n ) { int sum ; sum = ( int ) ( Math . Pow ( 10 , n + 1 ) - 10 - ( 9 * n ) ) / 81 ; return sum ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( summation ( n ) ) ; } }
Sum of the Series 1 + x / 1 + x ^ 2 / 2 + x ^ 3 / 3 + . . + x ^ n / n | C # program to find sum of series 1 + x ^ 2 / 2 + x ^ 3 / 3 + ... . + x ^ n / n ; Java code to print the sum of the given series ; Driver code
using System ; class GFG { static float sum ( int x , int n ) { double i , total = 1.0 , multi = x ; for ( i = 1 ; i <= n ; i ++ ) { total = total + multi / i ; multi = multi * x ; } return ( float ) total ; } public static void Main ( ) { int x = 2 ; int n = 5 ; Console . WriteLine ( sum ( x , n ) ) ; } }
Find n | C # program to find the nth term of the series 1 2 2 3 3 3 ... ; function to solve the quadratic equation ; calculating the Nth term ; driver code to check the above function
using System ; class Series { static int term ( int n ) { int x = ( ( ( 1 ) + ( int ) Math . Sqrt ( 1 + ( 8 * n ) ) ) / 2 ) ; return x ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( term ( n ) ) ; } }
Deserium Number | C # program to check whether a number is Deserium number or not ; Returns count of digits in n . ; Returns true if x is Diserium ; Compute powers of digits from right to left . ; If sum of powers is same as given number . ; Driver code
using System ; class Deserium { static int countDigits ( int n ) { int c = 0 ; do { c ++ ; n = n / 10 ; } while ( n != 0 ) ; return c ; } static bool isDeserium ( int x ) { int temp = x ; int p = countDigits ( x ) ; int sum = 0 ; while ( x != 0 ) { int digit = x % 10 ; sum += ( int ) Math . Pow ( digit , p ) ; p -- ; x = x / 10 ; } return ( sum == temp ) ; } public static void Main ( ) { int x = 135 ; if ( isDeserium ( x ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Largest number by which given 3 numbers should be divided such that they leaves same remainder | C # program to find the largest numbers that leads to same remainder when divides given three sorted numbers ; gcd function ; function return number which divides these three number and leaves same remainder . ; We find the differences of all three pairs ; Return GCD of three differences . ; Driver code
using System ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int sameRemainder ( int a , int b , int c ) { int a1 = ( b - a ) , b1 = ( c - b ) , c1 = ( c - a ) ; return gcd ( a1 , gcd ( b1 , c1 ) ) ; } public static void Main ( ) { int a = 62 , b = 132 , c = 237 ; Console . WriteLine ( sameRemainder ( a , b , c ) ) ; } }
Find combined mean and variance of two series | C # program to find combined mean and variance of two series . ; Function to find mean of series . ; Function to find the standard deviation of series . ; Function to find combined variance of two different series . ; mean1 and mean2 are the mean of two arrays . ; sd1 and sd2 are the standard deviation of two array . ; combinedMean is variable to store the combined mean of both array . ; d1_square and d2_square are the combined mean deviation . ; combinedVar is variable to store combined variance of both array . ; Driver code ; Function call to combined mean .
using System ; class GFG { static float mean ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; float mean = ( float ) sum / n ; return mean ; } static float sd ( int [ ] 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 ) ) ; float sdd = sum / n ; return sdd ; } static float combinedVariance ( int [ ] arr1 , int [ ] arr2 , int n , int m ) { float mean1 = mean ( arr1 , n ) ; float mean2 = mean ( arr2 , m ) ; Console . Write ( " Mean1 : ▁ " + mean1 + " ▁ " ) ; Console . WriteLine ( " Mean2 : ▁ " + mean2 ) ; float sd1 = sd ( arr1 , n ) ; float sd2 = sd ( arr2 , m ) ; Console . Write ( " StandardDeviation1 : ▁ " + sd1 + " ▁ " ) ; Console . WriteLine ( " StandardDeviation2 : ▁ " + sd2 + " ▁ " ) ; float combinedMean = ( float ) ( n * mean1 + m * mean2 ) / ( n + m ) ; Console . WriteLine ( " Combined ▁ Mean : ▁ " + combinedMean + " ▁ " ) ; float d1_square = ( mean1 - combinedMean ) * ( mean1 - combinedMean ) ; float d2_square = ( mean2 - combinedMean ) * ( mean2 - combinedMean ) ; Console . Write ( " d1 ▁ square : ▁ " + d1_square + " ▁ " ) ; Console . WriteLine ( " d2 _ square : ▁ " + d2_square ) ; float combinedVar = ( n * ( sd1 + d1_square ) + m * ( sd2 + d2_square ) ) / ( n + m ) ; return combinedVar ; } public static void Main ( ) { int [ ] arr1 = { 23 , 45 , 34 , 78 , 12 , 76 , 34 } ; int [ ] arr2 = { 65 , 67 , 34 , 23 , 45 } ; int n = arr1 . Length ; int m = arr2 . Length ; Console . WriteLine ( " Combined ▁ Variance : ▁ " + combinedVariance ( arr1 , arr2 , n , m ) ) ; } }
Check if a large number is divisible by 13 or not | C # program to check whether a number is divisible by 13 or not . ; Returns true if number is divisible by 13 else returns false ; Append required 0 s . at the beginning . ; Same as strcat ( num , "00" ) ; in c . ; Same as strcat ( num , "0" ) ; in c . ; Alternatively add / subtract digits in group of three to result . ; Store group of three numbers in group variable . ; Generate alternate series of plus and minus ; Driver code
using System ; class GFG { static bool checkDivisibility ( string num ) { int length = num . Length ; if ( length == 1 && num [ 0 ] == '0' ) return true ; if ( length % 3 == 1 ) { num += "00" ; length += 2 ; } else if ( length % 3 == 2 ) { num += "0" ; length += 1 ; } int sum = 0 , p = 1 ; for ( int i = length - 1 ; i >= 0 ; i -- ) { int group = 0 ; group += num [ i -- ] - '0' ; group += ( num [ i -- ] - '0' ) * 10 ; group += ( num [ i ] - '0' ) * 100 ; sum = sum + group * p ; p *= ( - 1 ) ; } sum = Math . Abs ( sum ) ; return ( sum % 13 == 0 ) ; } static void Main ( ) { string number = "83959092724" ; if ( checkDivisibility ( number ) ) Console . Write ( number + " ▁ is ▁ divisible ▁ by ▁ 13 . " ) ; else Console . Write ( number + " ▁ is ▁ not ▁ divisible ▁ by ▁ 13 . " ) ; } }