codeparrot/xlcost-text-to-code huggingface dataset:
Check whether a given matrix is orthogonal or not | C # code to check whether a matrix is orthogonal or not ; Function to check orthogonalilty ; Find transpose ; Find product of a [ ] [ ] and its transpose ; Since we are multiplying transpose of itself . We use ; Check if product is identity matrix ; Driver code
using System ; class GFG { static bool isOrthogonal ( int [ , ] a , int m , int n ) { if ( m != n ) return false ; int [ , ] trans = new int [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) trans [ i , j ] = a [ j , i ] ; int [ , ] prod = new int [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { int sum = 0 ; for ( int k = 0 ; k < n ; k ++ ) { sum = sum + ( a [ i , k ] * a [ j , k ] ) ; } prod [ i , j ] = sum ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i != j && prod [ i , j ] != 0 ) return false ; if ( i == j && prod [ i , j ] != 1 ) return false ; } } return true ; } static public void Main ( ) { int [ , ] a = { { 1 , 0 , 0 } , { 0 , 1 , 0 } , { 0 , 0 , 1 } } ; if ( isOrthogonal ( a , 3 , 3 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check if given number is perfect square | C # program to find if x is a perfect square . ; Find floating point value of square root of x . ; if product of square root is equal , then return T / F ; Driver code
using System ; class GFG { static bool isPerfectSquare ( double x ) { if ( x >= 0 ) { double sr = Math . Sqrt ( x ) ; return ( sr * sr == x ) ; } return false ; } public static void Main ( ) { double x = 2502 ; if ( isPerfectSquare ( x ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Program to print GP ( Geometric Progression ) | C # program to print GP . ; function to print GP ; Driver code ; starting number ; Common ratio ; N th term to be find
using System ; class GFG { static void printGP ( int a , int r , int n ) { int curr_term ; for ( int i = 0 ; i < n ; i ++ ) { curr_term = a * ( int ) Math . Pow ( r , i ) ; Console . Write ( curr_term + " ▁ " ) ; } } public static void Main ( ) { int a = 2 ; int r = 3 ; int n = 5 ; printGP ( a , r , n ) ; } }
HCF of array of fractions ( or rational numbers ) | C # program to find HCF of array of rational numbers ( fractions ) . ; hcf of two number ; find hcf of numerator series ; return hcf of numerator ; find lcm of denominator series ; ans contains LCM of arr [ 0 , 1 ] , . . arr [ i , 1 ] ; return lcm of denominator ; Core Function ; found hcf of numerator ; found lcm of denominator ; return result ; Driver code ; Initialize the every row with size 2 ( 1 for numerator and 2 for denominator ) ; function for calculate the result ; print the result
using System ; class GFG { static int gcd ( int a , int b ) { if ( a % b == 0 ) return b ; else return ( gcd ( b , a % b ) ) ; } static int findHcf ( int [ , ] arr , int size ) { int ans = arr [ 0 , 0 ] ; for ( int i = 1 ; i < size ; i ++ ) ans = gcd ( ans , arr [ i , 0 ] ) ; return ( ans ) ; } static int findLcm ( int [ , ] arr , int size ) { int ans = arr [ 0 , 1 ] ; for ( int i = 1 ; i < size ; i ++ ) ans = ( ( ( arr [ i , 1 ] * ans ) ) / ( gcd ( arr [ i , 1 ] , ans ) ) ) ; return ( ans ) ; } static int [ ] hcfOfFraction ( int [ , ] arr , int size ) { int hcf_of_num = findHcf ( arr , size ) ; int lcm_of_deno = findLcm ( arr , size ) ; int [ ] result = new int [ 2 ] ; result [ 0 ] = hcf_of_num ; result [ 1 ] = lcm_of_deno ; for ( int i = result [ 0 ] / 2 ; i > 1 ; i -- ) { if ( ( result [ 1 ] % i == 0 ) && ( result [ 0 ] % i == 0 ) ) { result [ 1 ] /= i ; result [ 0 ] /= i ; } } return ( result ) ; } public static void Main ( String [ ] args ) { int size = 4 ; int [ , ] arr = new int [ size , size ] ; arr [ 0 , 0 ] = 9 ; arr [ 0 , 1 ] = 10 ; arr [ 1 , 0 ] = 12 ; arr [ 1 , 1 ] = 25 ; arr [ 2 , 0 ] = 18 ; arr [ 2 , 1 ] = 35 ; arr [ 3 , 0 ] = 21 ; arr [ 3 , 1 ] = 40 ; int [ ] result = hcfOfFraction ( arr , size ) ; Console . WriteLine ( result [ 0 ] + " , ▁ " + result [ 1 ] ) ; } }
Space efficient iterative method to Fibonacci number | C # code to find nth fibonacci ; get second MSB ; consectutively set all the bits ; returns the second MSB ; Multiply function ; Function to calculate F [ ] [ ] raise to the power n ; Base case ; take 2D array to store number 's ; run loop till MSB > 0 ; To return fibonacci number ; Driver Code ; Given n
using System ; class GFG { static int getMSB ( int n ) { n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; return ( ( n + 1 ) >> 2 ) ; } static void multiply ( int [ , ] F , int [ , ] M ) { int x = F [ 0 , 0 ] * M [ 0 , 0 ] + F [ 0 , 1 ] * M [ 1 , 0 ] ; int y = F [ 0 , 0 ] * M [ 0 , 1 ] + F [ 0 , 1 ] * M [ 1 , 1 ] ; int z = F [ 1 , 0 ] * M [ 0 , 0 ] + F [ 1 , 1 ] * M [ 1 , 0 ] ; int w = F [ 1 , 0 ] * M [ 0 , 1 ] + F [ 1 , 1 ] * M [ 1 , 1 ] ; F [ 0 , 0 ] = x ; F [ 0 , 1 ] = y ; F [ 1 , 0 ] = z ; F [ 1 , 1 ] = w ; } static void power ( int [ , ] F , int n ) { if ( n == 0 n == 1 ) return ; int [ , ] M = { { 1 , 1 } , { 1 , 0 } } ; for ( int m = getMSB ( n ) ; m > 0 ; m = m >> 1 ) { multiply ( F , F ) ; if ( ( n & m ) > 0 ) { multiply ( F , M ) ; } } } static int fib ( int n ) { int [ , ] F = { { 1 , 1 } , { 1 , 0 } } ; if ( n == 0 ) return 0 ; power ( F , n - 1 ) ; return F [ 0 , 0 ] ; } static public void Main ( ) { int n = 6 ; Console . WriteLine ( fib ( n ) ) ; } }
Stern | C # program to print Brocot Sequence ; loop to create sequence ; adding sum of considered element and it 's precedent ; adding next considered element ; printing sequence . . ; Driver code ; adding first two element in the sequence
using System ; using System . Collections . Generic ; class GFG { static void SternSequenceFunc ( List < int > BrocotSequence , int n ) { for ( int i = 1 ; BrocotSequence . Count < n ; i ++ ) { int considered_element = BrocotSequence [ i ] ; int precedent = BrocotSequence [ i - 1 ] ; BrocotSequence . Add ( considered_element + precedent ) ; BrocotSequence . Add ( considered_element ) ; } for ( int i = 0 ; i < 15 ; ++ i ) Console . Write ( BrocotSequence [ i ] + " ▁ " ) ; } static void Main ( ) { int n = 15 ; List < int > BrocotSequence = new List < int > ( ) ; BrocotSequence . Add ( 1 ) ; BrocotSequence . Add ( 1 ) ; SternSequenceFunc ( BrocotSequence , n ) ; } }
Counting numbers whose difference from reverse is a product of k | C # program to Count the numbers within a given range in which when you subtract a number from its reverse , the difference is a product of k ; function to check if the number and its reverse have their absolute difference divisible by k ; reverse the number ; Driver code
using System ; class GFG { static bool isRevDiffDivisible ( int x , int k ) { int n = x ; int m = 0 ; while ( x > 0 ) { m = m * 10 + x % 10 ; x /= 10 ; } return ( Math . Abs ( n - m ) % k == 0 ) ; } static int countNumbers ( int l , int r , int k ) { int count = 0 ; for ( int i = l ; i <= r ; i ++ ) if ( isRevDiffDivisible ( i , k ) ) ++ count ; return count ; } public static void Main ( ) { int l = 35 , r = 45 , k = 5 ; Console . WriteLine ( countNumbers ( l , r , k ) ) ; } }
Check for Amicable Pair | C # program to check if two numbers are Amicable or not . ; Function to calculate sum of all proper divisors of a given number ; Sum of divisors ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' n ' ; if both divisors are same then add it once else add both ; Add 1 and n to result as above loop considers proper divisors greater than 1. ; Returns true if x and y are Amicable else false . ; Driver Code
using System ; class GFG { static int divSum ( int n ) { int result = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == ( n / i ) ) result += i ; else result += ( i + n / i ) ; } } return ( result + 1 ) ; } static bool areAmicable ( int x , int y ) { if ( divSum ( x ) != y ) return false ; return ( divSum ( y ) == x ) ; } public static void Main ( ) { int x = 220 , y = 284 ; if ( areAmicable ( x , y ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Program to print non square numbers | C # program to print first n non - square numbers . ; Function to check perfect square ; function to print all non square number ; variable which stores the count ; not perfect square ; Driver code
using System ; class GFG { static bool isPerfectSquare ( int n ) { if ( n < 0 ) return false ; double root = Math . Round ( ( double ) ( Math . Sqrt ( n ) ) ) ; return n == root * root ; } static void printnonsquare ( int n ) { int count = 0 ; for ( int i = 1 ; count < n ; ++ i ) { if ( ! isPerfectSquare ( i ) ) { Console . Write ( i + " ▁ " ) ; count ++ ; } } } static public void Main ( ) { int n = 10 ; printnonsquare ( n ) ; } }
Program to print non square numbers | C # program to print first n non - square numbers . ; Returns n - th non - square number . ; loop to print non squares below n ; Driver code
using System ; class GFG { static int nonsquare ( int n ) { return n + ( int ) ( 0.5 + ( Math . Sqrt ( n ) ) ) ; } static void printNonSquare ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( nonsquare ( i ) + " ▁ " ) ; } public static void Main ( ) { int n = 10 ; printNonSquare ( n ) ; } }
Ludic Numbers | C # code to print Lucid number smaller than or equal to n . ; Returns a list containing all Ludic numbers smaller than or equal to n . ; ludics list contain all the ludic numbers ; Here we have to start with index 1 and will remove nothing from the list ; Here first item should be included in the list and the deletion is referred by this first item in the loop . ; remove_index variable is used to store the next index which we want to delete ; Removing the next item ; remove_index is updated so that we get the next index for deletion ; Driver code
using System ; using System . Collections ; class GFG { public static ArrayList getLudic ( int n ) { ArrayList ludics = new ArrayList ( ) ; for ( int i = 1 ; i <= n ; i ++ ) ludics . Add ( i ) ; for ( int index = 1 ; index < ludics . Count ; index ++ ) { int first_ludic = ( int ) ludics [ index ] ; int remove_index = index + first_ludic ; while ( remove_index < ludics . Count ) { ludics . Remove ( ludics [ remove_index ] ) ; remove_index = remove_index + first_ludic - 1 ; } } return ludics ; } public static void Main ( string [ ] srgs ) { int n = 25 ; ArrayList tmp = getLudic ( n ) ; Console . Write ( " [ " ) ; foreach ( int x in tmp ) { Console . Write ( x + " , ▁ " ) ; } Console . Write ( " ] " ) ; } }
Prime Triplet | C # program to find prime triplets smaller than or equal to n . ; function to detect prime number ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; function to print prime triplets ; Finding all primes from 1 to n ; triplets of form ( p , p + 2 , p + 6 ) ; triplets of form ( p , p + 4 , p + 6 ) ; Driver Code
using System ; class GFG { static void sieve ( int n , bool [ ] prime ) { for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == false ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = true ; } } } static void printPrimeTriplets ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; sieve ( n , prime ) ; Console . WriteLine ( " The ▁ prime ▁ triplets ▁ " + " from ▁ 1 ▁ to ▁ " + n + " ▁ are ▁ : " ) ; for ( int i = 2 ; i <= n - 6 ; ++ i ) { if ( ! prime [ i ] && ! prime [ i + 2 ] && ! prime [ i + 6 ] ) Console . WriteLine ( i + " ▁ " + ( i + 2 ) + " ▁ " + ( i + 6 ) ) ; else if ( ! prime [ i ] && ! prime [ i + 4 ] && ! prime [ i + 6 ] ) Console . WriteLine ( i + " ▁ " + ( i + 4 ) + " ▁ " + ( i + 6 ) ) ; } } public static void Main ( ) { int n = 25 ; printPrimeTriplets ( n ) ; } }
Program to compare two fractions | C # program to find max between two Rational numbers ; Constructor ; Get max of the two fractions ; Declare nume1 and nume2 for get the value of first numerator and second numerator ; Compute ad - bc ; Driver function
using System ; class Fraction { int num , den ; Fraction ( int n , int d ) { num = n ; den = d ; } static Fraction maxFraction ( Fraction first , Fraction sec ) { int a = first . num ; int b = first . den ; int c = sec . num ; int d = sec . den ; int Y = a * d - b * c ; return ( Y > 0 ) ? first : sec ; } public static void Main ( ) { Fraction first = new Fraction ( 3 , 2 ) ; Fraction sec = new Fraction ( 3 , 4 ) ; Fraction res = maxFraction ( first , sec ) ; Console . WriteLine ( res . num + " / " + res . den ) ; } }
Find the nearest odd and even perfect squares of odd and even array elements respectively | C # program for the above approach ; Function to find the nearest even and odd perfect squares for even and odd array elements ; Traverse the array ; Calculate square root of current array element ; If both are of same parity ; Otherwise ; Driver Code
using System ; class GFG { static void nearestPerfectSquare ( int [ ] arr , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int sr = ( int ) Math . Sqrt ( arr [ i ] ) ; if ( ( sr & 1 ) == ( arr [ i ] & 1 ) ) Console . Write ( ( sr * sr ) + " ▁ " ) ; else { sr ++ ; Console . Write ( ( sr * sr ) + " ▁ " ) ; } } } static public void Main ( ) { int [ ] arr = { 6 , 3 , 2 , 15 } ; int N = arr . Length ; nearestPerfectSquare ( arr , N ) ; } }
Program to check if N is a Pentagonal Number | C # program to check pentagonal numbers . ; Function to determine if N is pentagonal or not . ; Substitute values of i in the formula . ; Driver Code
using System ; class GFG { static bool isPentagonal ( int N ) { int i = 1 , M ; do { M = ( 3 * i * i - i ) / 2 ; i += 1 ; } while ( M < N ) ; return ( M == N ) ; } public static void Main ( ) { int N = 12 ; if ( isPentagonal ( N ) ) Console . Write ( N + " ▁ is ▁ pentagonal ▁ " ) ; else Console . Write ( N + " ▁ is ▁ not ▁ pentagonal " ) ; } }
Sum of fourth powers of the first n natural numbers | C # program to find the sum of forth powers of first n natural numbers ; Return the sum of forth power of first n natural numbers ; Driver code
using System ; class GFG { static long fourthPowerSum ( int n ) { long sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum = sum + ( i * i * i * i ) ; return sum ; } public static void Main ( ) { int n = 6 ; Console . WriteLine ( fourthPowerSum ( n ) ) ; } }
Sum of fourth powers of the first n natural numbers | C # Program to find the sum of forth powers of first n natural numbers ; Return the sum of forth power of first n natural numbers ; Driver Code
using System ; class GFG { static long fourthPowerSum ( int n ) { return ( ( 6 * n * n * n * n * n ) + ( 15 * n * n * n * n ) + ( 10 * n * n * n ) - n ) / 30 ; } public static void Main ( ) { int n = 6 ; Console . Write ( fourthPowerSum ( n ) ) ; } }
Find unit digit of x raised to power y | C # code to find the unit digit of x raised to power y . ; find unit digit ; Get last digit of x ; Last cyclic modular value ; here we simply return the unit digit or the power of a number ; Driver code ; get unit digit number here we pass the unit digit of x and the last cyclicity number that is y % 4
using System ; class GFG { static int unitnumber ( int x , int y ) { x = x % 10 ; if ( y != 0 ) y = y % 4 + 4 ; return ( ( ( int ) ( Math . Pow ( x , y ) ) ) % 10 ) ; } public static void Main ( ) { int x = 133 , y = 5 ; Console . WriteLine ( unitnumber ( x , y ) ) ; } }
Aliquot sum | C # program for aliquot sum ; Function to calculate sum of all proper divisors ; Driver Code
using System ; class GFG { static int aliquotSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i < n ; i ++ ) if ( n % i == 0 ) sum += i ; return sum ; } public static void Main ( ) { int n = 12 ; Console . WriteLine ( aliquotSum ( n ) ) ; } }
Multiplication of two complex numbers given as strings | C # program to multiply two complex numbers given as strings . ; Spiting the real and imaginary parts of the given complex strings based on ' + ' and ' i ' symbols . ; Storing the real part of complex string a ; Storing the imaginary part of complex string a ; Storing the real part of complex string b ; Storing the imaginary part of complex string b ; Returns the product . ; Driver code
using System ; using System . Text . RegularExpressions ; class GfG { public static String complexNumberMultiply ( String a , String b ) { String [ ] x = Regex . Split ( a , @"\+ i" ) ; String [ ] y = Regex . Split ( b , @"\+ i" ) ; int a_real = Int32 . Parse ( x [ 0 ] ) ; int a_img = Int32 . Parse ( x [ 1 ] ) ; int b_real = Int32 . Parse ( y [ 0 ] ) ; int b_img = Int32 . Parse ( y [ 1 ] ) ; return ( a_real * b_real - a_img * b_img ) + " + " + ( a_real * b_img + a_img * b_real ) + " i " ; } public static void Main ( String [ ] argc ) { String str1 = "1 + 1i " ; String str2 = "1 + 1i " ; Console . WriteLine ( complexNumberMultiply ( str1 , str2 ) ) ; } }
Average of Squares of Natural Numbers | C # program to get the Average of squareof first n natural numbers ; Function to calculate average ; Driver Code
using System ; public class GFG { static float AvgofSquareN ( int n ) { return ( float ) ( ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; } static public void Main ( String [ ] args ) { int n = 2 ; Console . WriteLine ( AvgofSquareN ( n ) ) ; } }
Program to implement Simpson 's 3/8 rule | C # Code to implement Simpson 's rule ; Given function to be integrated ; Function to perform calculations ; Calculates value till integral limit ; Driver program to test above function
using System ; class GFG { static float func ( float x ) { return ( 1 / ( 1 + x * x ) ) ; } static float calculate ( float lower_limit , float upper_limit , int interval_limit ) { float interval_size = ( upper_limit - lower_limit ) / interval_limit ; float sum = func ( lower_limit ) + func ( upper_limit ) ; for ( int i = 1 ; i < interval_limit ; i ++ ) { if ( i % 3 == 0 ) sum = sum + 2 * func ( lower_limit + i * interval_size ) ; else sum = sum + 3 * func ( lower_limit + i * interval_size ) ; } return ( 3 * interval_size / 8 ) * sum ; } public static void Main ( ) { int interval_limit = 10 ; float lower_limit = 1 ; float upper_limit = 10 ; float integral_res = calculate ( lower_limit , upper_limit , interval_limit ) ; Console . WriteLine ( integral_res ) ; } }
Container with Most Water | C # code for Max Water Container ; Calculating the max area ; Driver code
using System ; class GFG { public static int maxArea ( int [ ] a ) { int Area = 0 ; for ( int i = 0 ; i < a . Length ; i ++ ) { for ( int j = i + 1 ; j < a . Length ; j ++ ) { Area = Math . Max ( Area , Math . Min ( a [ i ] , a [ j ] ) * ( j - i ) ) ; } } return Area ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 5 , 4 , 3 } ; int [ ] b = { 3 , 1 , 2 , 4 , 5 } ; Console . WriteLine ( maxArea ( a ) ) ; Console . Write ( maxArea ( b ) ) ; } }
Program for focal length of a lens | C # program to determine the focal length of a lens ; Function to determine the focal length of a lens ; Driver code ; variable to store the distance between the lens and the image ; variable to store the distance between the lens and the object
using System ; class GFG { static float focal_length ( float image_distance , float object_distance ) { return 1 / ( ( 1 / image_distance ) + ( 1 / object_distance ) ) ; } public static void Main ( ) { float image_distance = 2 ; float object_distance = 50 ; Console . WriteLine ( " Focal ▁ length ▁ of ▁ a ▁ lens ▁ is ▁ " + focal_length ( image_distance , object_distance ) + " ▁ units . " ) ; } }
Count numbers in range L | Java program to Count numbers in range L - R that are divisible by all of its non - zero digits ; check if the number is divisible by the digits . ; function to calculate the number of numbers ; Driver function
using System ; class GFG { static bool check ( int n ) { int m = n ; while ( n != 0 ) { int r = n % 10 ; if ( r > 0 ) if ( ( m % r ) != 0 ) return false ; n /= 10 ; } return true ; } static int count ( int l , int r ) { int ans = 0 ; for ( int i = l ; i <= r ; i ++ ) if ( check ( i ) ) ans += 1 ; return ans ; } public static void Main ( ) { int l = 10 , r = 20 ; Console . WriteLine ( count ( l , r ) ) ; } }
Sum of the Series 1 / ( 1 * 2 ) + 1 / ( 2 * 3 ) + 1 / ( 3 * 4 ) + 1 / ( 4 * 5 ) + . . . . . | C # program to find the sum of given series ; Function to find the sum of given series ; Computing sum term by term ; Driver Code
using System ; class demo { public static double sumOfTheSeries ( int n ) { double sum = 0.0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += 1.0 / ( i * ( i + 1 ) ) ; return sum ; } public static void Main ( ) { int n = 10 ; Console . Write ( sumOfTheSeries ( n ) ) ; } }
Sum of series ( n / 1 ) + ( n / 2 ) + ( n / 3 ) + ( n / 4 ) + ... ... . + ( n / n ) | C # program to find sum of given series ; Function to find sum of series ; Driver code
using System ; class GFG { static long sum ( long n ) { long root = ( long ) Math . Sqrt ( n ) ; long ans = 0 ; for ( int i = 1 ; i <= root ; i ++ ) ans += n / i ; ans = 2 * ans - ( root * root ) ; return ans ; } public static void Main ( ) { long n = 35 ; Console . Write ( sum ( n ) ) ; } }
Sum of the series 2 + ( 2 + 4 ) + ( 2 + 4 + 6 ) + ( 2 + 4 + 6 + 8 ) + â €¦ â €¦ + ( 2 + 4 + 6 + 8 + â €¦ . + 2 n ) | C # implementation to find the sum of the given series ; function to find the sum of the given series ; sum of 1 st n natural numbers ; sum of squares of 1 st n natural numbers ; required sum ; Driver program to test above
using System ; class GFG { static int sumOfTheSeries ( int n ) { int sum_n = ( n * ( n + 1 ) / 2 ) ; int sum_sq_n = ( n * ( n + 1 ) / 2 ) * ( 2 * n + 1 ) / 3 ; return ( sum_n + sum_sq_n ) ; } public static void Main ( ) { int n = 5 ; Console . Write ( " Sum ▁ = ▁ " + sumOfTheSeries ( n ) ) ; } }
Sum of squares of binomial coefficients | C # Program to find the sum of square of binomial coefficient . ; Return the sum of square of binomial coefficient ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; Calculate value using previously stored values ; Finding the sum of square of binomial coefficient . ; Driver function
using System ; class GFG { static int sumofsquare ( int n ) { int [ , ] C = new int [ n + 1 , n + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . Min ( i , n ) ; j ++ ) { if ( j == 0 j == i ) C [ i , j ] = 1 ; else C [ i , j ] = C [ i - 1 , j - 1 ] + C [ i - 1 , j ] ; } } int sum = 0 ; for ( i = 0 ; i <= n ; i ++ ) sum += ( C [ n , i ] * C [ n , i ] ) ; return sum ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( sumofsquare ( n ) ) ; } }
Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n | C # Program to find sum of series 1 + 2 + 2 + 3 + . . . + n ; Function that find sum of series . ; Driver Code ; Function call
using System ; public class GfG { static int sumOfSeries ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= i ; j ++ ) sum = sum + i ; return sum ; } public static void Main ( ) { int n = 10 ; Console . Write ( sumOfSeries ( n ) ) ; } }
Find sum of even index binomial coefficients | C # Program to find sum of even index term ; Return the sum of even index term ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; else Calculate value using previously stored values ; finding sum of even index term . ; Driver Program
using System ; class GFG { static int evenSum ( int n ) { int [ , ] C = new int [ n + 1 , n + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . Min ( i , n ) ; j ++ ) { if ( j == 0 j == i ) C [ i , j ] = 1 ; else C [ i , j ] = C [ i - 1 , j - 1 ] + C [ i - 1 , j ] ; } } int sum = 0 ; for ( i = 0 ; i <= n ; i += 2 ) sum += C [ n , i ] ; return sum ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( evenSum ( n ) ) ; } }
Program to print triangular number series till n | C # program to print triangular number series till n ; Function to find triangular number ; Driver Code
using System ; class GFG { static void triangular_series ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( i * ( i + 1 ) / 2 + " ▁ " ) ; } public static void Main ( ) { int n = 5 ; triangular_series ( n ) ; } }