codeparrot/xlcost-text-to-code huggingface dataset:
Sum of elements in range L | C # program to find the sum between L - R range by creating the array Efficient Approach ; Function to calculate the sum if n is even ; both l and r are to the left of mid ; first and last element ; Total number of terms in the sequence is r - l + 1 ; use of formula derived ; both l and r are to the right of mid ; first and last element ; Use of formula derived ; left is to the left of mid and right is to the right of mid ; Take two sums i . e left and right differently and add ; first and last element ; total terms ; no of terms ; The first even number is 2 ; The last element is given by 2 * ( r - n / 2 ) ; formula applied ; Function to calculate the sum if n is odd ; take ceil value if n is odd ; both l and r are to the left of mid ; first and last element ; number of terms ; formula ; both l and r are to the right of mid ; first and last term , ; no of terms ; formula used ; If l is on left and r on right ; calculate separate sums ; first half ; calculate terms ; second half ; add both halves ; Function to find the sum between L and R ; If n is even ; If n is odd ; Driver Code
using System ; class GFG { static int sumeven ( int n , int l , int r ) { int sum = 0 ; int mid = n / 2 ; if ( r <= mid ) { int first = ( 2 * l - 1 ) ; int last = ( 2 * r - 1 ) ; int no_of_terms = r - l + 1 ; sum = ( ( no_of_terms ) * ( ( first + last ) ) ) / 2 ; } else if ( l >= mid ) { int first = ( 2 * ( l - n / 2 ) ) ; int last = ( 2 * ( r - n / 2 ) ) ; int no_of_terms = r - l + 1 ; sum = ( ( no_of_terms ) * ( ( first + last ) ) ) / 2 ; } else { int sumleft = 0 , sumright = 0 ; int first_term1 = ( 2 * l - 1 ) ; int last_term1 = ( 2 * ( n / 2 ) - 1 ) ; int no_of_terms1 = n / 2 - l + 1 ; sumleft = ( ( no_of_terms1 ) * ( ( first_term1 + last_term1 ) ) ) / 2 ; int first_term2 = 2 ; int last_term2 = ( 2 * ( r - n / 2 ) ) ; int no_of_terms2 = r - mid ; sumright = ( ( no_of_terms2 ) * ( ( first_term2 + last_term2 ) ) ) / 2 ; sum = ( sumleft + sumright ) ; } return sum ; } static int sumodd ( int n , int l , int r ) { int mid = n / 2 + 1 ; int sum = 0 ; if ( r <= mid ) { int first = ( 2 * l - 1 ) ; int last = ( 2 * r - 1 ) ; int no_of_terms = r - l + 1 ; sum = ( ( no_of_terms ) * ( ( first + last ) ) ) / 2 ; } else if ( l > mid ) { int first = ( 2 * ( l - mid ) ) ; int last = ( 2 * ( r - mid ) ) ; int no_of_terms = r - l + 1 ; sum = ( ( no_of_terms ) * ( ( first + last ) ) ) / 2 ; } else { int sumleft = 0 , sumright = 0 ; int first_term1 = ( 2 * l - 1 ) ; int last_term1 = ( 2 * mid - 1 ) ; int no_of_terms1 = mid - l + 1 ; sumleft = ( ( no_of_terms1 ) * ( ( first_term1 + last_term1 ) ) ) / 2 ; int first_term2 = 2 ; int last_term2 = ( 2 * ( r - mid ) ) ; int no_of_terms2 = r - mid ; sumright = ( ( no_of_terms2 ) * ( ( first_term2 + last_term2 ) ) ) / 2 ; sum = ( sumleft + sumright ) ; } return sum ; } static int rangesum ( int n , int l , int r ) { if ( n % 2 == 0 ) return sumeven ( n , l , r ) ; else return sumodd ( n , l , r ) ; } public static void Main ( ) { int n = 12 ; int l = 1 , r = 11 ; Console . WriteLine ( rangesum ( n , l , r ) ) ; } }
Program to find the Interior and Exterior Angle of a Regular Polygon | C # program to find the interior and exterior angle of a given polygon ; function to find the interior and exterior angle ; formula to find the interior angle ; formula to find the exterior angle ; Displaying the output ; Driver code ; Function calling
using System ; class GFG { static void findAngle ( int n ) { int interiorAngle , exteriorAngle ; interiorAngle = ( n - 2 ) * 180 / n ; exteriorAngle = 360 / n ; Console . Write ( " Interior ▁ angle : ▁ " + interiorAngle + " STRNEWLINE " ) ; Console . Write ( " Exterior ▁ angle : ▁ " + exteriorAngle ) ; } public static void Main ( ) { int n = 10 ; findAngle ( n ) ; } }
Program to calculate distance between two points in 3 D | C # program to find distance between two points in 3 D . ; Function for distance ; Driver code ; function call for distance
using System ; class GFG { static void distance ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ) { double d = Math . Pow ( ( Math . Pow ( x2 - x1 , 2 ) + Math . Pow ( y2 - y1 , 2 ) + Math . Pow ( z2 - z1 , 2 ) * 1.0 ) , 0.5 ) ; Console . WriteLine ( " Distance ▁ is ▁ STRNEWLINE " + d ) ; return ; } public static void Main ( ) { float x1 = 2 ; float y1 = - 5 ; float z1 = 7 ; float x2 = 3 ; float y2 = 4 ; float z2 = 5 ; distance ( x1 , y1 , z1 , x2 , y2 , z2 ) ; } }
Check if the large number formed is divisible by 41 or not | C # program to check a large number divisible by 41 or not ; Check if a number is divisible by 41 or not ; array to store all the digits ; base values ; calculate remaining digits ; calculate answer ; check for divisibility ; Driver Code
using System ; class GFG { static bool DivisibleBy41 ( int first , int second , int c , int n ) { int [ ] digit = new int [ n ] ; digit [ 0 ] = first ; digit [ 1 ] = second ; for ( int i = 2 ; i < n ; i ++ ) digit [ i ] = ( digit [ i - 1 ] * c + digit [ i - 2 ] ) % 10 ; int ans = digit [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) ans = ( ans * 10 + digit [ i ] ) % 41 ; if ( ans % 41 == 0 ) return true ; else return false ; } public static void Main ( ) { int first = 1 , second = 2 , c = 1 , n = 3 ; if ( DivisibleBy41 ( first , second , c , n ) ) Console . Write ( " YES " ) ; else Console . Write ( " NO " ) ; } }
Program to print pentatope numbers upto Nth term | C # program to generate Pentatope Number series ; Function to generate nth tetrahedral number ; Function to print pentatope number series upto nth term . ; Initialize prev as 0. It store the sum of all previously generated pentatope numbers ; Loop to print pentatope series ; Find ith tetrahedral number ; Add ith tetrahedral number to sum of all previously generated tetrahedral number to get ith pentatope number ; Update sum of all previously generated tetrahedral number ; Driver code ; Function call to print pentatope number series
using System ; public class GFG { static int findTetrahedralNumber ( int n ) { return ( ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ) ; } static void printSeries ( int n ) { int prev = 0 ; int curr ; for ( int i = 1 ; i <= n ; i ++ ) { curr = findTetrahedralNumber ( i ) ; curr = curr + prev ; Console . Write ( curr + " ▁ " ) ; prev = curr ; } } static public void Main ( ) { int n = 10 ; printSeries ( n ) ; } }
Program to print pentatope numbers upto Nth term | C # program to print Pentatope number series . ; Function to print pentatope series up to nth term ; Loop to print pentatope number series ; calculate and print ith pentatope number ; Driver code ; Function call to print pentatope number series
using System ; public class GFG { static void printSeries ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { int num = ( i * ( i + 1 ) * ( i + 2 ) * ( i + 3 ) / 24 ) ; Console . Write ( num + " ▁ " ) ; } } static public void Main ( ) { int n = 10 ; printSeries ( n ) ; } }
Find unique pairs such that each element is less than or equal to N | C # program for finding the required pairs ; Finding the number of unique pairs ; Using the derived formula ; Printing the unique pairs ; Driver code
using System ; class GFG { static int No_Of_Pairs ( int N ) { int i = 1 ; while ( ( i * i * i ) + ( 2 * i * i ) + i <= N ) i ++ ; return ( i - 1 ) ; } static void print_pairs ( int pairs ) { int i = 1 , mul ; for ( i = 1 ; i <= pairs ; i ++ ) { mul = i * ( i + 1 ) ; Console . WriteLine ( " Pair ▁ no . ▁ " + i + " ▁ - - > ▁ ( " + ( mul * i ) + " , ▁ " + mul * ( i + 1 ) + " ) " ) ; } } static void Main ( ) { int N = 500 , pairs ; pairs = No_Of_Pairs ( N ) ; Console . WriteLine ( " No . ▁ of ▁ pairs ▁ = ▁ " + pairs ) ; print_pairs ( pairs ) ; } }
Program to print tetrahedral numbers upto Nth term | C # program to generate tetrahedral number series ; function to generate nth triangular number ; function to print tetrahedral number series up to n ; Initialize prev as 0. It store the sum of all previously generated triangular number ; Loop to print series ; Find ithh triangular number ; Add ith triangular number to sum of all previously generated triangular number to get ith tetrahedral number ; Update sum of all previously generated triangular number ; Driver code ; function call to print series
using System ; public class GFG { static long findTriangularNumber ( int n ) { return ( n * ( n + 1 ) ) / 2 ; } static void printSeries ( int n ) { long prev = 0 ; long curr ; for ( int i = 1 ; i <= n ; i ++ ) { curr = findTriangularNumber ( i ) ; curr = curr + prev ; Console . Write ( curr + " ▁ " ) ; prev = curr ; } } static public void Main ( ) { int n = 10 ; printSeries ( n ) ; } }
Program to print tetrahedral numbers upto Nth term | C # program to generate series of tetrahedral numbers ; function to print tetrahedral number series up to n ; loop to print series ; Calculate and print ith tetrahedral number ; Driver code ; function call to print series
using System ; public class GFG { static void printSeries ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { int num = i * ( i + 1 ) * ( i + 2 ) / 6 ; Console . Write ( num + " ▁ " ) ; } } static public void Main ( ) { int n = 10 ; printSeries ( n ) ; } }
Number of odd and even results for every value of x in range [ min , max ] after performing N steps | C # program to print Number of odd / even results for every value of x in range [ min , end ] after performing N steps ; Function that prints the number of odd and even results ; If constant at layer i is even , beven is true , otherwise false . If the coefficient of x at layer i is even , aeven is true , otherwise false . ; If any of the coefficients at any layer is found to be even , then the product of all the coefficients will always be even . ; Checking whether the constant added after all layers is even or odd . ; Assuming input x is even . ; Assuming input x is odd . ; Displaying the counts . ; Driver Code
using System ; class GFG { static void count_even_odd ( int min , int max , int [ , ] steps ) { int a , b , even , odd ; bool beven = true , aeven = false ; int n = 2 ; for ( int i = 0 ; i < n ; i ++ ) { a = steps [ i , 0 ] ; b = steps [ i , 1 ] ; if ( ! ( aeven || ( a & 1 ) > 0 ) ) aeven = true ; if ( beven ) { if ( ( b & 1 ) > 0 ) beven = false ; } else if ( ! ( ( a & 1 ) > 0 ) ) { if ( ! ( ( b & 1 ) > 0 ) ) beven = true ; } else { if ( ( b & 1 ) > 0 ) beven = true ; } } if ( beven ) { even = ( int ) max / 2 - ( int ) ( min - 1 ) / 2 ; odd = 0 ; } else { even = ( int ) max / 2 - ( int ) ( min - 1 ) / 2 ; odd = 0 ; } if ( ! ( beven ^ aeven ) ) even += max - min + 1 - ( int ) max / 2 + ( int ) ( min - 1 ) / 2 ; else odd += max - min + 1 - ( int ) max / 2 + ( int ) ( min - 1 ) / 2 ; Console . Write ( " even ▁ = ▁ " + even + " , ▁ odd ▁ = ▁ " + odd ) ; } public static void Main ( ) { int min = 1 , max = 4 ; int [ , ] steps = { { 1 , 2 } , { 3 , 4 } } ; count_even_odd ( min , max , steps ) ; } }
Maximum number of ones in a N * N matrix with given constraints | C # program to get Maximum Number of ones in a matrix with given constraints ; Function that returns the maximum number of ones ; Minimum number of zeroes ; Totol cells = square of the size of the matrices ; Initialising the answer ; Driver code ; Initialising the variables
using System ; class GFG { static int getMaxOnes ( int n , int x ) { int zeroes = ( n / x ) ; zeroes = zeroes * zeroes ; int total = n * n ; int ans = total - zeroes ; return ans ; } static public void Main ( ) { int n = 5 ; int x = 2 ; Console . WriteLine ( getMaxOnes ( n , x ) ) ; } }
Minimum operations required to make all the elements distinct in an array | C # program to find Minimum number of changes to make array distinct ; Function that returns minimum number of changes ; Hash - table to store frequency ; Increase the frequency of elements ; Traverse in the map to sum up the ( occurrences - 1 ) of duplicate elements ; Driver Code
using System ; using System . Collections . Generic ; class geeks { public static int minimumOperations ( int [ ] a , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( a [ i ] ) ) { var val = mp [ a [ i ] ] ; mp . Remove ( a [ i ] ) ; mp . Add ( a [ i ] , val + 1 ) ; } else { mp . Add ( a [ i ] , 1 ) ; } } int count = 0 ; foreach ( KeyValuePair < int , int > entry in mp ) { if ( entry . Value > 1 ) { count += ( entry . Value - 1 ) ; } } return count ; } public static void Main ( String [ ] args ) { int [ ] a = { 2 , 1 , 2 , 3 , 3 , 4 , 3 } ; int n = a . Length ; Console . WriteLine ( minimumOperations ( a , n ) ) ; } }
Check if a M | C # program to check if M - th fibonacci divides N - th fibonacci ; exceptional case for F ( 2 ) ; if none of the above cases , hence not divisible ; Driver Code
using System ; class GFG { static void check ( int n , int m ) { if ( n == 2 m == 2 n % m == 0 ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } public static void Main ( ) { int m = 3 , n = 9 ; check ( n , m ) ; } }
Surface Area and Volume of Hexagonal Prism | C # program to find the Surface Area and Volume of Hexagonal Prism . ; Function to calculate Surface area ; Formula to calculate surface area ; Display surface area ; Function to calculate Volume ; formula to calculate Volume ; Display Volume ; Driver code ; surface area function call ; volume function call
using System ; class GFG { static void findSurfaceArea ( float a , float h ) { float Area ; Area = 6 * a * h + 3 * ( float ) ( Math . Sqrt ( 3 ) ) * a * a ; Console . WriteLine ( " Surface ▁ Area : ▁ " + Area ) ; } static void findVolume ( float a , float h ) { float Volume ; Volume = 3 * ( float ) ( Math . Sqrt ( 3 ) ) * a * a * h / 2 ; Console . WriteLine ( " Volume : ▁ " + Volume ) ; } public static void Main ( ) { float a = 5 , h = 10 ; findSurfaceArea ( a , h ) ; findVolume ( a , h ) ; } }
Minimum number of mails required to distribute all the questions | C # code to find the minimum number of mails ; Function returns the min no of mails required ; Using the formula derived above ; Driver Code ; no of questions ; no of students ; maximum no of questions a mail can hold ; Calling function
using System ; class GFG { static double MinimumMail ( int n , int k , int x ) { double m = ( n - 1 ) + Math . Ceiling ( ( n - 1 ) * 1.0 / x ) * ( n - 1 ) + Math . Ceiling ( n * 1.0 / x ) * ( k - n ) ; return m ; } public static void Main ( ) { int N = 4 ; int K = 9 ; int X = 2 ; Console . WriteLine ( ( int ) MinimumMail ( N , K , X ) + " STRNEWLINE " ) ; } }
Program to find the Area of an Ellipse | C # program to find area of an Ellipse . ; Function to find area of an ellipse . ; formula to find the area of an Ellipse . ; Display the result ; Driver code
using System ; class GFG { static void findArea ( float a , float b ) { float Area ; Area = ( float ) 3.142 * a * b ; Console . WriteLine ( " Area : ▁ " + Area ) ; } public static void Main ( ) { float a = 5 , b = 4 ; findArea ( a , b ) ; } }
Compute power of power k times % m | C # program for computing x ^ x ^ x ^ x . . % m ; Function to compute the given value ; compute power k times ; Driver Code ; Calling function
using System ; class GFG { static int calculate ( int x , int k , int m ) { int result = x ; k -- ; while ( k -- > 0 ) { result = ( int ) Math . Pow ( result , x ) ; if ( result > m ) result %= m ; } return result ; } static public void Main ( ) { int x = 5 , k = 2 , m = 3 ; Console . WriteLine ( calculate ( x , k , m ) ) ; } }
Recursive program to check if number is palindrome or not | Recursive C # program to check if the number is palindrome or not ; recursive function that returns the reverse of digits ; base case ; stores the reverse of a number ; Driver Code
using System ; class GFG { static int rev ( int n , int temp ) { if ( n == 0 ) return temp ; temp = ( temp * 10 ) + ( n % 10 ) ; return rev ( n / 10 , temp ) ; } public static void Main ( ) { int n = 121 ; int temp = rev ( n , 0 ) ; if ( temp == n ) Console . WriteLine ( " yes " ) ; else Console . WriteLine ( " no " ) ; } }
Program to find greater value between a ^ n and b ^ n | C # code for finding greater between the a ^ n and b ^ n ; Function to find the greater value ; If n is even ; Driver code
using System ; class GFG { static void findGreater ( int a , int b , int n ) { if ( ! ( ( n & 1 ) > 0 ) ) { a = Math . Abs ( a ) ; b = Math . Abs ( b ) ; } if ( a == b ) Console . WriteLine ( " a ^ n ▁ is ▁ " + " equal ▁ to ▁ b ^ n " ) ; else if ( a > b ) Console . WriteLine ( " a ^ n ▁ is ▁ greater ▁ " + " than ▁ b ^ n " ) ; else Console . WriteLine ( " b ^ n ▁ is ▁ greater ▁ " + " than ▁ a ^ n " ) ; } public static void Main ( ) { int a = 12 , b = 24 , n = 5 ; findGreater ( a , b , n ) ; } }
Print first n Fibonacci Numbers using direct formula | C # code to print fibonacci numbers till n using direct formula . \ ; Function to calculate fibonacci using recurrence relation formula ; Using direct formula ; Driver code
using System ; public class GFG { static void fibonacci ( double n ) { double fib ; for ( double i = 0 ; i < n ; i ++ ) { fib = ( Math . Pow ( ( 1 + Math . Sqrt ( 5 ) ) , i ) - Math . Pow ( ( 1 - Math . Sqrt ( 5 ) ) , i ) ) / ( Math . Pow ( 2 , i ) * Math . Sqrt ( 5 ) ) ; Console . Write ( ( int ) fib + " ▁ " ) ; } } static public void Main ( ) { double n = 8 ; fibonacci ( n ) ; } }
Centered Hexadecagonal Number | C # Program to find nth centered hexadecagonal number ; centered hexadecagonal function ; Formula to calculate nth centered hexadecagonal number ; Driver Code
using System ; class GFG { static int center_hexadecagonal_num ( int n ) { return 8 * n * n - 8 * n + 1 ; } static public void Main ( ) { int n = 2 ; Console . Write ( n + " th ▁ centered ▁ " + " hexadecagonal ▁ number : ▁ " ) ; Console . WriteLine ( center_hexadecagonal_num ( n ) ) ; n = 12 ; Console . Write ( n + " th ▁ centered ▁ " + " hexadecagonal ▁ number : ▁ " ) ; Console . WriteLine ( center_hexadecagonal_num ( n ) ) ; } }
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 . ; Return true if odd ; Driver Code
using System ; class GFG { public static int findNature ( int a , int b , int n ) { int [ ] seq = new int [ 100 ] ; seq [ 0 ] = a ; seq [ 1 ] = b ; for ( int i = 2 ; i <= n ; i ++ ) seq [ i ] = seq [ i - 1 ] + seq [ i - 2 ] ; if ( ( seq [ n ] & 1 ) != 0 ) return 1 ; else return 0 ; } public static void Main ( ) { int a = 2 , b = 4 ; int n = 3 ; if ( findNature ( a , b , n ) == 1 ) Console . Write ( " Odd ▁ " ) ; else Console . Write ( " Even ▁ " ) ; } }
Program to compare m ^ n and n ^ m | C # program to compare which is greater m ^ n or n ^ m ; function to compare m ^ n and n ^ m ; m ^ n ; n ^ m ; Driver Code ; function call to compare m ^ n and n ^ m
using System ; class GFG { static void check ( ulong m , ulong n ) { double RHS = m * ( double ) Math . Log ( n ) ; double LHS = n * ( double ) Math . Log ( m ) ; if ( LHS > RHS ) Console . Write ( " m ^ n ▁ > ▁ n ^ m " ) ; else if ( LHS < RHS ) Console . Write ( " m ^ n ▁ < ▁ n ^ m " ) ; else Console . Write ( " m ^ n ▁ = ▁ n ^ m " ) ; } static public void Main ( ) { ulong m = 987654321 , n = 123456987 ; check ( m , n ) ; } }
Hilbert Matrix | C # program for Hilbert Matrix ; Function that generates a Hilbert matrix ; using the formula to generate hilbert matrix ; Driver code
using System ; class GFG { static void printMatrix ( int n ) { float [ , ] H = new float [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { H [ i , j ] = ( float ) 1.0 / ( ( i + 1 ) + ( j + 1 ) - ( float ) 1.0 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) Console . Write ( H [ i , j ] + " ▁ " ) ; Console . WriteLine ( " " ) ; } } public static void Main ( ) { int n = 3 ; printMatrix ( n ) ; } }
Find the GCD that lies in given range | C # Program to find the Greatest Common divisor of two number which is in given range ; Return the greatest common divisor of two numbers ; Return the gretest common divisor of a and b which lie in the given range . ; Loop from 1 to sqrt ( GCD ( a , b ) . ; if i divides the GCD ( a , b ) , then find maximum of three numbers res , i and g / i ; Driven Program
using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int maxDivisorRange ( int a , int b , int l , int h ) { int g = gcd ( a , b ) ; int res = - 1 ; for ( int i = l ; i * i <= g && i <= h ; i ++ ) if ( g % i == 0 ) res = Math . Max ( res , Math . Max ( i , g / i ) ) ; return res ; } public static void Main ( ) { int a = 3 , b = 27 , l = 1 , h = 5 ; Console . WriteLine ( maxDivisorRange ( a , b , l , h ) ) ; } }
Number expressed as sum of five consecutive integers | C # Program to check if a number can be expressed as sum of five consecutive integers . ; function to check if a number can be expressed as sum of five consecutive integers . ; if n is 0 ; if n is positive , increment loop by 1. ; if n is negative , decrement loop by 1. ; Running loop from 0 to n - 4 ; check if sum of five consecutive integer is equal to n . ; Driver Program
using System ; class GFG { static void checksum ( int n ) { if ( n == 0 ) { Console . Write ( " - 2 ▁ - 1 ▁ 0 ▁ 1 ▁ 2" ) ; return ; } int inc ; if ( n > 0 ) inc = 1 ; else inc = - 1 ; for ( int i = 0 ; i <= n - 4 ; i += inc ) { if ( i + i + 1 + i + 2 + i + 3 + i + 4 == n ) { Console . Write ( ( i ) + " ▁ " + ( i + 1 ) + " ▁ " + ( i + 2 ) + " ▁ " + ( i + 3 ) + " ▁ " + ( i + 4 ) ) ; return ; } } Console . WriteLine ( " - 1" ) ; } public static void Main ( ) { int n = 15 ; checksum ( n ) ; } }
Number expressed as sum of five consecutive integers | C # Program to check if a number can be expressed as sum of five consecutive integer . ; function to check if a number can be expressed as sum of five consecutive integers . ; if n is multiple of 5 ; else print " - 1" . ; Driver Program
using System ; class GFG { static void checksum ( int n ) { if ( n % 5 == 0 ) Console . WriteLine ( ( n / 5 - 2 ) + " ▁ " + ( n / 5 - 1 ) + " ▁ " + ( n / 5 ) + " ▁ " + ( n / 5 + 1 ) + " ▁ " + ( n / 5 + 2 ) ) ; else Console . WriteLine ( " - 1" ) ; } public static void Main ( ) { int n = 15 ; checksum ( n ) ; } }
Number of Transpositions in a Permutation | C # Program to find the number of transpositions in a permutation ; This array stores which element goes to which position ; This function returns the size of a component cycle ; If it is already visited ; This functio returns the number of transpositions in the permutation ; Initializing visited [ ] array ; building the goesTo [ ] array ; Driver Code
using System ; class GFG { static int N = 1000001 ; static int [ ] visited = new int [ N ] ; static int [ ] goesTo = new int [ N ] ; static int dfs ( int i ) { if ( visited [ i ] == 1 ) return 0 ; visited [ i ] = 1 ; int x = dfs ( goesTo [ i ] ) ; return ( x + 1 ) ; } static int noOfTranspositions ( int [ ] P , int n ) { for ( int i = 1 ; i <= n ; i ++ ) visited [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) goesTo [ P [ i ] ] = i + 1 ; int transpositions = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( visited [ i ] == 0 ) { int ans = dfs ( i ) ; transpositions += ans - 1 ; } } return transpositions ; } public static void Main ( ) { int [ ] permutation = { 5 , 1 , 4 , 3 , 2 } ; int n = permutation . Length ; Console . WriteLine ( noOfTranspositions ( permutation , n ) ) ; } }
n | C # program to find n - th term of series ; Function to find the nth term of series ; Loop to add 4 th powers ; Driver code
using System ; class GFG { static int sumOfSeries ( int n ) { int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) ans += i * i * i * i ; return ans ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( sumOfSeries ( n ) ) ; } }
Number of unmarked integers in a special sieve | C # Program to determine the number of unmarked integers in a special sieve ; Driver Code
using System ; class GFG { static int countUnmarked ( int N ) { if ( N % 2 == 0 ) return N / 2 ; else return N / 2 + 1 ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( " Number ▁ of ▁ unmarked ▁ " + " elements : ▁ " + countUnmarked ( N ) ) ; } }