codeparrot/xlcost-text-to-code huggingface dataset:
Check if given number is a power of d where d is a power of 2 | C # program to find if a number is power of d where d is power of 2. ; Function to count the number of ways to paint N * 3 grid based on given conditions ; Check if there is only one bit set in n ; count 0 bits before set bit ; If count is a multiple of log2 ( d ) then return true else false ; If there are more than 1 bit set then n is not a power of 4 ; Driver Code
using System ; class GFG { static int Log2n ( int n ) { return ( n > 1 ) ? 1 + Log2n ( n / 2 ) : 0 ; } static bool isPowerOfd ( int n , int d ) { int count = 0 ; if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) { while ( n > 1 ) { n >>= 1 ; count += 1 ; } return ( count % ( Log2n ( d ) ) == 0 ) ; } return false ; } static void Main ( ) { int n = 64 , d = 8 ; if ( isPowerOfd ( n , d ) ) Console . WriteLine ( " { 0 } ▁ is ▁ a ▁ " + " power ▁ of ▁ { 1 } " , n , d ) ; else Console . WriteLine ( " { 0 } ▁ is ▁ not ▁ a " + " ▁ power ▁ of ▁ { 1 } " , n , d ) ; } }
Total nodes traversed in Euler Tour Tree | C # program to check the number of nodes in Euler Tour tree . ; Adjacency list representation of tree ; Function to add edges to tree ; Program to check if calculated Value is equal to 2 * size - 1 ; Add out - degree of each node ; Driver Code ; Constructing 1 st tree from example ; Out_deg [ node [ i ] ] is equal to adj [ i ] . Count ; clear previous stored tree ; Constructing 2 nd tree from example ; Out_deg [ node [ i ] ] is equal to adj [ i ] . Count
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 1001 ; static List < int > [ ] adj = new List < int > [ MAX ] ; static void add_edge ( int u , int v ) { adj [ u ] . Add ( v ) ; } static void checkTotalNumberofNodes ( int actualAnswer , int size ) { int calculatedAnswer = size ; for ( int i = 1 ; i <= size ; i ++ ) calculatedAnswer += adj [ i ] . Count ; if ( actualAnswer == calculatedAnswer ) Console . Write ( " Calculated ▁ Answer ▁ is ▁ " + calculatedAnswer + " ▁ and ▁ is ▁ Equal ▁ to ▁ Actual ▁ Answer STRNEWLINE " ) ; else Console . Write ( " Calculated ▁ Answer ▁ " + " is ▁ Incorrect STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { for ( int i = 0 ; i < MAX ; i ++ ) adj [ i ] = new List < int > ( ) ; int N = 8 ; add_edge ( 1 , 2 ) ; add_edge ( 1 , 3 ) ; add_edge ( 2 , 4 ) ; add_edge ( 2 , 5 ) ; add_edge ( 3 , 6 ) ; add_edge ( 3 , 7 ) ; add_edge ( 6 , 8 ) ; checkTotalNumberofNodes ( 2 * N - 1 , N ) ; for ( int i = 1 ; i <= N ; i ++ ) adj [ i ] . Clear ( ) ; N = 9 ; add_edge ( 1 , 2 ) ; add_edge ( 1 , 3 ) ; add_edge ( 2 , 4 ) ; add_edge ( 2 , 5 ) ; add_edge ( 2 , 6 ) ; add_edge ( 3 , 9 ) ; add_edge ( 5 , 7 ) ; add_edge ( 5 , 8 ) ; checkTotalNumberofNodes ( 2 * N - 1 , N ) ; } }
Octahedral Number | C # program to find nth Octahedral number ; Function to find octahedral number ; Formula to calculate nth octahedral number and return it into main function . ; Driver Code ; print result
using System ; class GFG { static int octahedral_num ( int n ) { return n * ( 2 * n * n + 1 ) / 3 ; } static public void Main ( ) { int n = 5 ; Console . Write ( n + " th ▁ Octahedral " + " ▁ number : ▁ " ) ; Console . WriteLine ( octahedral_num ( n ) ) ; } }
Centered tetrahedral number | C # Program to find nth Centered tetrahedral number ; Function to find centered Centered tetrahedral number ; Formula to calculate nth Centered tetrahedral number and return it into main function . ; Driver Code
using System ; class GFG { static int centeredTetrahedralNumber ( int n ) { return ( 2 * n + 1 ) * ( n * n + n + 3 ) / 3 ; } public static void Main ( ) { int n = 6 ; Console . WriteLine ( centeredTetrahedralNumber ( n ) ) ; } }
Swapping four variables without temporary variable | C # program to swap 4 variables without using temporary variable . ; swapping a and b variables ; swapping b and c variables ; swapping c and d variables ; Driver Code ; initialising variables ; Function call
using System ; class GFG { static void swap ( int a , int b , int c , int d ) { a = a + b ; b = a - b ; a = a - b ; b = b + c ; c = b - c ; b = b - c ; c = c + d ; d = c - d ; c = c - d ; Console . WriteLine ( " values ▁ after ▁ " + " swapping ▁ are ▁ : ▁ " ) ; Console . WriteLine ( " a ▁ = ▁ " + a ) ; Console . WriteLine ( " b ▁ = ▁ " + b ) ; Console . WriteLine ( " c ▁ = ▁ " + c ) ; Console . WriteLine ( " d ▁ = ▁ " + d ) ; } public static void Main ( ) { int a = 1 ; int b = 2 ; int c = 3 ; int d = 4 ; Console . WriteLine ( " values ▁ before ▁ " + " swapping ▁ are ▁ : ▁ " ) ; Console . WriteLine ( " a ▁ = ▁ " + a ) ; Console . WriteLine ( " b ▁ = ▁ " + b ) ; Console . WriteLine ( " c ▁ = ▁ " + c ) ; Console . WriteLine ( " d ▁ = ▁ " + d ) ; Console . WriteLine ( " " ) ; swap ( a , b , c , d ) ; } }
Sum of first n natural 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 ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += i * ( i + 1 ) / 2 ; return sum ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( seriesSum ( n ) ) ; } }
Centrosymmetric Matrix | C # Program to check whether given matrix is centrosymmetric or not . ; Finding the middle row of the matrix ; for each row upto middle row . ; If each element and its corresponding element is not equal then return false . ; Driven Program
using System ; class GFG { static bool checkCentrosymmetricted ( int n , int [ , ] m ) { int mid_row ; if ( ( n & 1 ) > 0 ) mid_row = n / 2 + 1 ; else mid_row = n / 2 ; for ( int i = 0 ; i < mid_row ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( m [ i , j ] != m [ n - i - 1 , n - j - 1 ] ) return false ; } } return true ; } public static void Main ( ) { int n = 3 ; int [ , ] m = { { 1 , 3 , 5 } , { 6 , 8 , 6 } , { 5 , 3 , 1 } } ; if ( checkCentrosymmetricted ( n , m ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Centered triangular number | C # Program to find the nth Centered Triangular number ; function for Centered Triangular number ; formula for find Centered Triangular number nth term ; Driver Code ; For 3 rd Centered Triangular number ; For 12 th Centered Triangular number
using System ; class GFG { static int Centered_Triangular_num ( int n ) { return ( 3 * n * n + 3 * n + 2 ) / 2 ; } static public void Main ( ) { int n = 3 ; Console . WriteLine ( Centered_Triangular_num ( n ) ) ; n = 12 ; Console . WriteLine ( Centered_Triangular_num ( n ) ) ; } }
Array with GCD of any of its subset belongs to the given array | C # implementation to generate the required array ; Function to return gcd of a and b ; Function to find gcd of array of numbers ; Function to generate the array with required constraints . ; computing GCD of the given set ; Solution exists if GCD of array is equal to the minimum element of the array ; Printing the built array ; Driver Code ; Taking in the input and initializing the set STL set in cpp has a property that it maintains the elements in sorted order , thus we do not need to sort them externally ; Calling the computing function .
using System ; using System . Collections . Generic ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int findGCD ( List < int > arr , int n ) { int result = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) result = gcd ( arr [ i ] , result ) ; return result ; } static void compute ( List < int > arr , int n ) { List < int > answer = new List < int > ( ) ; int GCD_of_array = findGCD ( arr , n ) ; if ( GCD_of_array == arr [ 0 ] ) { answer . Add ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { answer . Add ( arr [ 0 ] ) ; answer . Add ( arr [ i ] ) ; } for ( int i = 0 ; i < answer . Count ; i ++ ) Console . Write ( answer [ i ] + " ▁ " ) ; } else Console . Write ( " No ▁ array ▁ " + " can ▁ be ▁ build " ) ; } static void Main ( ) { int n = 3 ; int [ ] input = new int [ ] { 2 , 5 , 6 , 7 , 11 } ; HashSet < int > GCD = new HashSet < int > ( input ) ; List < int > arr = new List < int > ( ) ; foreach ( int b in GCD ) arr . Add ( b ) ; compute ( arr , n ) ; } }
Combinatorics on ordered trees | C # code to find the number of ordered trees with given number of edges and leaves ; Function returns value of Binomial Coefficient C ( n , k ) ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; Calculate value using previously stored values ; Function to calculate the number of trees with exactly k leaves . ; Function to calculate total number of nodes of degree d in these trees . ; Function to calculate the number of trees in which the root has degree r . ; Driver program to test above functions ; Number of trees having 3 edges and exactly 2 leaves ; Number of nodes of degree 3 in a tree having 4 edges ; Number of trees having 3 edges where root has degree 2
using System ; class GFG { static int binomialCoeff ( int n , int k ) { int [ , ] C = new int [ n + 1 , k + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . Min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i , j ] = 1 ; else C [ i , j ] = C [ i - 1 , j - 1 ] + C [ i - 1 , j ] ; } } return C [ n , k ] ; } static int k_Leaves ( int n , int k ) { int ans = ( binomialCoeff ( n , k ) * binomialCoeff ( n , k - 1 ) ) / n ; Console . WriteLine ( " Number ▁ of ▁ trees ▁ " + " having ▁ 4 ▁ edges ▁ and ▁ exactly ▁ 2 ▁ " + " leaves ▁ : ▁ " + ans ) ; return 0 ; } static int numberOfNodes ( int n , int d ) { int ans = binomialCoeff ( 2 * n - 1 - d , n - 1 ) ; Console . WriteLine ( " Number ▁ of ▁ nodes ▁ " + " of ▁ degree ▁ 1 ▁ in ▁ a ▁ tree ▁ having ▁ 4 ▁ " + " edges ▁ : ▁ " + ans ) ; return 0 ; } static int rootDegreeR ( int n , int r ) { int ans = r * binomialCoeff ( 2 * n - 1 - r , n - 1 ) ; ans = ans / n ; Console . WriteLine ( " Number ▁ of ▁ trees ▁ " + " having ▁ 4 ▁ edges ▁ where ▁ root ▁ has " + " ▁ degree ▁ 2 ▁ : ▁ " + ans ) ; return 0 ; } public static void Main ( ) { k_Leaves ( 3 , 2 ) ; numberOfNodes ( 3 , 1 ) ; rootDegreeR ( 3 , 2 ) ; } }
Repeated Unit Divisibility | C # program to find least value of k for which R ( k ) is divisible by n ; To find least value of k ; To check n is coprime or not ; to store the R ( k ) mod n and 10 ^ k mod n value ; Driver code
using System ; public class GFG { public static int repUnitValue ( int n ) { if ( n % 2 == 0 n % 5 == 0 ) return 0 ; int rem = 1 ; int power = 1 ; int k = 1 ; while ( rem % n != 0 ) { k ++ ; power = power * 10 % n ; rem = ( rem + power ) % n ; } return k ; } public static void Main ( ) { int n = 13 ; Console . Write ( repUnitValue ( n ) ) ; } }
First N natural can be divided into two sets with given difference and co | C # code to determine whether numbers 1 to N can be divided into two sets such that absolute difference between sum of these two sets is M and these two sum are co - prime ; function that returns boolean value on the basis of whether it is possible to divide 1 to N numbers into two sets that satisfy given conditions . ; initializing total sum of 1 to n numbers ; since ( 1 ) total_sum = sum_s1 + sum_s2 and ( 2 ) m = sum_s1 - sum_s2 assuming sum_s1 > sum_s2 . solving these 2 equations to get sum_s1 and sum_s2 ; total_sum = sum_s1 + sum_s2 and therefore ; if total sum is less than the absolute difference then there is no way we can split n numbers into two sets so return false ; check if these two sums are integers and they add up to total sum and also if their absolute difference is m . ; Now if two sum are co - prime then return true , else return false . ; if two sums don 't add up to total  sum or if their absolute difference  is not m, then there is no way to  split n numbers, hence return false ; Driver code ; function call to determine answer
using System ; class GFG { static int GCD ( int a , int b ) { return b == 0 ? a : GCD ( b , a % b ) ; } static bool isSplittable ( int n , int m ) { int total_sum = ( n * ( n + 1 ) ) / 2 ; int sum_s1 = ( total_sum + m ) / 2 ; int sum_s2 = total_sum - sum_s1 ; if ( total_sum < m ) return false ; if ( sum_s1 + sum_s2 == total_sum && sum_s1 - sum_s2 == m ) return ( GCD ( sum_s1 , sum_s2 ) == 1 ) ; return false ; } public static void Main ( ) { int n = 5 , m = 7 ; if ( isSplittable ( n , m ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Making zero array by decrementing pairs of adjacent | C # implementation of the above approach ; converting array element into number ; Check if divisible by 11 ; Driver Code
using System ; class GFG { static bool isPossibleToZero ( int [ ] a , int n ) { int num = 0 ; for ( int i = 0 ; i < n ; i ++ ) num = num * 10 + a [ i ] ; return ( num % 11 == 0 ) ; } public static void Main ( ) { int [ ] arr = { 0 , 1 , 1 , 0 } ; int n = arr . Length ; if ( isPossibleToZero ( arr , n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Blum Integer | C # implementation to check If a number is a Blum integer ; Function to cheek if number is Blum Integer ; to store prime numbers from 2 to n ; If prime [ i ] is not changed , then it is a prime ; Update all multiples of p ; to check if the given odd integer is Blum Integer or not ; checking the factors are of 4 t + 3 form or not ; Driver code ; give odd integer greater than 20
using System ; class GFG { public static bool isBlumInteger ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) prime [ i ] = true ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * 2 ; j <= n ; j += i ) prime [ j ] = false ; } } for ( int i = 2 ; i <= n ; i ++ ) { if ( prime [ i ] ) { if ( ( n % i == 0 ) && ( ( i - 3 ) % 4 ) == 0 ) { int q = n / i ; return ( q != i && prime [ q ] && ( q - 3 ) % 4 == 0 ) ; } } } return false ; } static public void Main ( ) { int n = 249 ; if ( isBlumInteger ( n ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Program to calculate value of nCr | C # program To calculate The Value Of nCr ; Returns factorial of n ; Driver code
using System ; class GFG { static int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } public static void Main ( ) { int n = 5 , r = 3 ; Console . Write ( nCr ( n , r ) ) ; } }
Program to print the sum of the given nth term | C # program to illustrate ... Summation of series ; function to calculate sum of series ; Sum of n terms is n ^ 2 ; Driver code
using System ; class GFG { static int summingSeries ( long n ) { return ( int ) Math . Pow ( n , 2 ) ; } public static void Main ( ) { int n = 100 ; Console . Write ( " The ▁ sum ▁ of ▁ n ▁ term ▁ is : ▁ " + summingSeries ( n ) ) ; } }
Brahmagupta Fibonacci Identity | C # code to verify Brahmagupta Fibonacci identity ; represent the product as sum of 2 squares ; check identity criteria ; Driver code ; 1 ^ 2 + 2 ^ 2 ; 3 ^ 2 + 4 ^ 2 ; express product of sum of 2 squares as sum of ( sum of 2 squares )
using System ; class GFG { static void find_sum_of_two_squares ( int a , int b ) { int ab = a * b ; for ( int i = 0 ; i * i <= ab ; i ++ ) { for ( int j = i ; i * i + j * j <= ab ; j ++ ) { if ( i * i + j * j == ab ) Console . Write ( i + " ^ 2 ▁ + ▁ " + j + " ^ 2 ▁ = ▁ " + ab + " STRNEWLINE " ) ; } } } public static void Main ( ) { int a = 1 * 1 + 2 * 2 ; int b = 3 * 3 + 4 * 4 ; Console . Write ( " Representation ▁ of ▁ a ▁ * ▁ b ▁ " + " as ▁ sum ▁ of ▁ 2 ▁ squares : STRNEWLINE " ) ; find_sum_of_two_squares ( a , b ) ; } }
Tetrahedral Numbers | C # Program to find the nth tetrahedral number ; Function to find Tetrahedral Number ; Driver code
using System ; public class GFG { static int tetrahedralNumber ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ; } static public void Main ( ) { int n = 5 ; Console . WriteLine ( tetrahedralNumber ( n ) ) ; } }
Euler 's Four Square Identity | C # code to verify euler 's four square identity ; function to check euler four square identity ; loops checking the sum of squares ; sum of 2 squares ; sum of 3 squares ; sum of 4 squares ; product of 2 numbers represented as sum of four squares i , j , k , l ; product of 2 numbers a and b represented as sum of four squares i , j , k , l ; Driver code ; given numbers can be represented as sum of 4 squares By euler 's  four square identity  product also can be  represented as sum  of 4 squares
using System ; class GFG { static void check_euler_four_square_identity ( int a , int b , int ab ) { int s = 0 ; for ( int i = 0 ; i * i <= ab ; i ++ ) { s = i * i ; for ( int j = i ; j * j <= ab ; j ++ ) { s = j * j + i * i ; for ( int k = j ; k * k <= ab ; k ++ ) { s = k * k + j * j + i * i ; for ( int l = k ; l * l <= ab ; l ++ ) { s = l * l + k * k + j * j + i * i ; if ( s == ab ) { Console . Write ( " i ▁ = ▁ " + i + " STRNEWLINE " ) ; Console . Write ( " j ▁ = ▁ " + j + " STRNEWLINE " ) ; Console . Write ( " k ▁ = ▁ " + k + " STRNEWLINE " ) ; Console . Write ( " l ▁ = ▁ " + l + " STRNEWLINE " ) ; Console . Write ( " Product ▁ of ▁ " + a + " ▁ and ▁ " + b ) ; Console . Write ( " ▁ can ▁ be ▁ written " + " ▁ as ▁ sum ▁ of ▁ squares ▁ of ▁ i , ▁ " + " j , ▁ k , ▁ l STRNEWLINE " ) ; Console . Write ( ab + " ▁ = ▁ " ) ; Console . Write ( i + " * " + i + " ▁ + ▁ " ) ; Console . Write ( j + " * " + j + " ▁ + ▁ " ) ; Console . Write ( k + " * " + k + " ▁ + ▁ " ) ; Console . Write ( l + " * " + l + " STRNEWLINE " ) ; Console . Write ( " STRNEWLINE " ) ; } } } } } } static void Main ( ) { int ab = a * b ; check_euler_four_square_identity ( a , b , ab ) ; } }
Number of solutions to Modular Equations | C # Program to find number of possible values of X to satisfy A mod X = B ; Returns the number of divisors of ( A - B ) greater than B ; if N is divisible by i ; count only the divisors greater than B ; checking if a divisor isnt counted twice ; Utility function to calculate number of all possible values of X for which the modular equation holds true ; if A = B there are infinitely many solutions to equation or we say X can take infinitely many values > A . We return - 1 in this case ; if A < B , there are no possible values of X satisfying the equation ; the last case is when A > B , here we calculate the number of divisors of ( A - B ) , which are greater than B ; Wrapper function for numberOfPossibleWaysUtil ( ) ; if infinitely many solutions available ; Driver code
using System ; class GFG { static int calculateDivisors ( int A , int B ) { int N = ( A - B ) ; int noOfDivisors = 0 ; double a = Math . Sqrt ( N ) ; for ( int i = 1 ; i <= ( int ) ( a ) ; i ++ ) { if ( ( N % i ) == 0 ) { if ( i > B ) noOfDivisors ++ ; if ( ( N / i ) != i && ( N / i ) > B ) noOfDivisors ++ ; } } return noOfDivisors ; } static int numberOfPossibleWaysUtil ( int A , int B ) { if ( A == B ) return - 1 ; if ( A < B ) return 0 ; int noOfDivisors = 0 ; noOfDivisors = calculateDivisors ( A , B ) ; return noOfDivisors ; } public static void numberOfPossibleWays ( int A , int B ) { int noOfSolutions = numberOfPossibleWaysUtil ( A , B ) ; if ( noOfSolutions == - 1 ) { Console . Write ( " For ▁ A ▁ = ▁ " + A + " ▁ and ▁ B ▁ = ▁ " + B + " , ▁ X ▁ can ▁ take ▁ Infinitely ▁ many ▁ values " + " ▁ greater ▁ than ▁ " + A + " STRNEWLINE " ) ; } else { Console . Write ( " For ▁ A ▁ = ▁ " + A + " ▁ and ▁ B ▁ = ▁ " + B + " , ▁ X ▁ can ▁ take ▁ " + noOfSolutions + " ▁ values STRNEWLINE " ) ; } } public static void Main ( ) { int A = 26 , B = 2 ; numberOfPossibleWays ( A , B ) ; A = 21 ; B = 5 ; numberOfPossibleWays ( A , B ) ; } }
Perfect power ( 1 , 4 , 8 , 9 , 16 , 25 , 27 , ... ) | C # program to count number of numbers from 1 to n are of type x ^ y where x > 0 and y > 1 ; Function that keeps all the odd power numbers upto n ; We need exclude perfect squares . ; Return sum of odd and even powers . ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static long powerNumbers ( int n ) { HashSet < long > v = new HashSet < long > ( ) ; for ( long i = 2 ; i * i * i <= n ; i ++ ) { long j = i * i ; while ( j * i <= n ) { j *= i ; long s = ( long ) Math . Sqrt ( j ) ; if ( s * s != j ) v . Add ( j ) ; } } return v . Count + ( long ) Math . Sqrt ( n ) ; } static void Main ( ) { Console . Write ( powerNumbers ( 50 ) ) ; } }
Variance and standard | C # program to find mean and variance of a matrix . ; Function for calculating mean ; Calculating sum ; Returning mean ; Function for calculating variance ; subtracting mean from elements ; a [ i ] [ j ] = fabs ( a [ i ] [ j ] ) ; squaring each terms ; taking sum ; Driver Code ; declaring and initializing matrix ; for mean ; for variance ; for standard deviation ; displaying variance and deviation
using System ; class GFG { static int mean ( int [ , ] a , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) sum += a [ i , j ] ; return sum / ( n * n ) ; } static int variance ( int [ , ] a , int n , int m ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { a [ i , j ] -= m ; a [ i , j ] *= a [ i , j ] ; } } for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) sum += a [ i , j ] ; return sum / ( n * n ) ; } static public void Main ( ) { int [ , ] mat = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; int m = mean ( mat , 3 ) ; int var = variance ( mat , 3 , m ) ; double dev = ( int ) Math . Sqrt ( var ) ; Console . WriteLine ( " Mean : ▁ " + m ) ; Console . WriteLine ( " Variance : ▁ " + var ) ; Console . WriteLine ( " Deviation : ▁ " + dev ) ; } }
Find N Arithmetic Means between A and B | C # program to illustrate n arithmetic mean between A and B ; insert function for calculating the means ; Finding the value of d Common difference ; for finding N the Arithmetic mean between A and B ; Driver code
using System ; public class GFG { static void printAMeans ( int A , int B , int N ) { float d = ( float ) ( B - A ) / ( N + 1 ) ; for ( int i = 1 ; i <= N ; i ++ ) Console . Write ( ( A + i * d ) + " ▁ " ) ; } public static void Main ( ) { int A = 20 , B = 32 , N = 5 ; printAMeans ( A , B , N ) ; } }
Sum of the series 1.2 . 3 + 2.3 . 4 + ... + n ( n + 1 ) ( n + 2 ) | Efficient C # program to find sum of the series 1.2 . 3 + 2.3 . 4 + 3.4 . 5 + . . ; function to calculate sum of series ; Driver Code
using System ; class GFG { static int sumofseries ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) * ( n + 3 ) / 4 ) ; } public static void Main ( ) { Console . WriteLine ( sumofseries ( 3 ) ) ; } }
Largest number in [ 2 , 3 , . . n ] which is co | C # Largest number in [ 2 , 3 , . . n ] which is co - prime with numbers in [ 2 , 3 , . . m ] ; Returns true if i is co - prime with numbers in set [ 2 , 3 , ... m ] ; Running the loop till square root of n to reduce the time complexity from n ; Find the minimum of square root of n and m to run the loop until the smaller one ; Check from 2 to min ( m , sqrt ( n ) ) ; Function to find the largest number less than n which is Co - prime with all numbers from 2 to m ; Iterating from n to m + 1 to find the number ; checking every number for the given conditions ; The first number which satisfy the conditions is the answer ; If there is no number which satisfy the conditions , then print number does not exist . ; Driver Program
using System ; class GFG { static bool isValid ( long i , long m ) { long sq_i = ( long ) Math . Sqrt ( i ) ; long sq = Math . Min ( m , sq_i ) ; for ( long j = 2 ; j <= sq ; j ++ ) if ( i % j == 0 ) return false ; return true ; } static void findLargestNum ( long n , long m ) { for ( long i = n ; i > m ; i -- ) { if ( isValid ( i , m ) ) { Console . WriteLine ( i ) ; return ; } } Console . WriteLine ( " Number ▁ Doesn ' t ▁ Exists " ) ; } public static void Main ( ) { long n = 55 , m = 25 ; findLargestNum ( n , m ) ; } }