codeparrot/xlcost-text-to-code huggingface dataset:
Cutting a Rod | DP | A Dynamic Programming solution for Rod cutting problem ; Returns the best obtainable price for a rod of length n and price [ ] as prices of different pieces ; Build the table val [ ] in bottom up manner and return the last entry from the table ; Driver Code
using System ; class GFG { static int cutRod ( int [ ] price , int n ) { int [ ] val = new int [ n + 1 ] ; val [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int max_val = int . MinValue ; for ( int j = 0 ; j < i ; j ++ ) max_val = Math . Max ( max_val , price [ j ] + val [ i - j - 1 ] ) ; val [ i ] = max_val ; } return val [ n ] ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 5 , 8 , 9 , 10 , 17 , 17 , 20 } ; int size = arr . Length ; Console . WriteLine ( " Maximum ▁ Obtainable ▁ Value ▁ is ▁ " + cutRod ( arr , size ) ) ; } }
Modify array to another given array by replacing array elements with the sum of the array | C # program for the above approach ; Function to check if the arr [ ] can be converted to target [ ] by replacing any element in arr [ ] by the sum of arr [ ] ; Store the maximum element ; Store the index of the maximum element ; Traverse the array target [ ] ; If current element is greater than max ; If max element is 1 ; Traverse the array , target [ ] ; If current index is not equal to maximum element index ; Update max ; If max is less than or equal to 0 , ; Update the maximum element ; Recursively call the function ; Driver Code
using System ; class GFG { public static bool isPossible ( int [ ] target ) { int max = 0 ; int index = 0 ; for ( int i = 0 ; i < target . Length ; i ++ ) { if ( max < target [ i ] ) { max = target [ i ] ; index = i ; } } if ( max == 1 ) return true ; for ( int i = 0 ; i < target . Length ; i ++ ) { if ( i != index ) { max -= target [ i ] ; if ( max <= 0 ) return false ; } } target [ index ] = max ; return isPossible ( target ) ; } static public void Main ( ) { int [ ] target = { 9 , 3 , 5 } ; bool res = isPossible ( target ) ; if ( res ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }
Sum of all products of the Binomial Coefficients of two numbers up to K | C # implementation of the above approach ; Function returns nCr i . e . Binomial Coefficient ; Initialize res with 1 ; Since C ( n , r ) = C ( n , n - r ) ; Evaluating expression ; Driver Code
using System ; class GFG { static int nCr ( int n , int r ) { int res = 1 ; if ( r > n - r ) r = n - r ; for ( int i = 0 ; i < r ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } public static void Main ( ) { int n = 3 , m = 2 , k = 2 ; Console . Write ( nCr ( n + m , k ) ) ; } }
Check if N can be obtained from 1 by repetitively multiplying by 10 or 20 | C # program to check if N can be obtained from 1 by repetitive multiplication by 10 or 20 ; Function to check if N can be obtained or not ; Count and remove trailing zeroes ; Check if remaining N is a power of 2 ; To check the condition to prlong YES or NO ; Driver Code
using System ; class GFG { static void Is_possible ( long N ) { long C = 0 ; long D = 0 ; while ( N % 10 == 0 ) { N = N / 10 ; C += 1 ; } if ( Math . Pow ( 2 , ( long ) ( Math . Log ( N ) / ( Math . Log ( 2 ) ) ) ) == N ) { D = ( long ) ( Math . Log ( N ) / ( Math . Log ( 2 ) ) ) ; if ( C >= D ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } else Console . WriteLine ( " NO " ) ; } public static void Main ( ) { long N = 2000000000000L ; Is_possible ( N ) ; } }
Central polygonal numbers | C # program to find N - th term in the series ; Function to find N - th term in the series ; Driver code
using System ; class GFG { static void findNthTerm ( int n ) { Console . Write ( n * n - n + 1 ) ; } public static void Main ( ) { int N = 4 ; findNthTerm ( N ) ; } }
Anti | C # program for the above approach ; Iterative function to reverse digits of num ; Return the reversed num ; Function to calculate sum of reverse all proper divisors ; Final result of summation of divisors ; Find all divisors of num ; If ' i ' is divisor of ' num ' ; If both divisors are same then add it only once else add both ; Add 1 to the result as 1 is also a divisor ; Function to check if N is anti - perfect or not ; Driver Code ; Given Number N ; Function Call
using System ; class GFG { static int rev ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } static int divSum ( int num ) { int result = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += rev ( i ) ; else result += ( rev ( i ) + rev ( num / i ) ) ; } } return ( result + 1 ) ; } static Boolean isAntiPerfect ( int n ) { return divSum ( n ) == n ; } public static void Main ( String [ ] args ) { int N = 244 ; if ( isAntiPerfect ( N ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Program to print the series 1 , 3 , 4 , 8 , 15 , 27 , 50 â €¦ till N terms | C # implementation to print the N terms of the series whose three terms are given ; Function to print the series ; Generate the ith term and print it ; Driver Code ; Function call
using System ; class GFG { static void printSeries ( int n , int a , int b , int c ) { int d ; if ( n == 1 ) { Console . Write ( a + " ▁ " ) ; return ; } if ( n == 2 ) { Console . Write ( a + " ▁ " + b + " ▁ " ) ; return ; } Console . Write ( a + " ▁ " + b + " ▁ " + c + " ▁ " ) ; for ( int i = 4 ; i <= n ; i ++ ) { d = a + b + c ; Console . Write ( d + " ▁ " ) ; a = b ; b = c ; c = d ; } } public static void Main ( ) { int N = 7 , a = 1 , b = 3 ; int c = 4 ; printSeries ( N , a , b , c ) ; } }
Diameter of a Binary Indexed Tree with N nodes | C # implementation of the approach ; Function to find diameter of BIT with N + 1 nodes ; L is size of subtree just before subtree in which N lies ; H is the height of subtree just before subtree in which N lies ; Base Cases ; Size of subtree are power of 2 ; 3 Cases as explained in Approach ; Driver Code
using System ; class GFG { static int diameter ( int n ) { int L , H ; L = 1 ; H = 0 ; if ( n == 1 ) { return 1 ; } if ( n == 2 ) { return 2 ; } if ( n == 3 ) { return 3 ; } while ( L * 2 <= n ) { L *= 2 ; H ++ ; } if ( n >= L * 2 - 1 ) return 2 * H + 1 ; else if ( n >= L + ( L / 2 ) - 1 ) return 2 * H ; return 2 * H - 1 ; } public static void Main ( String [ ] args ) { int n = 15 ; Console . WriteLine ( diameter ( n ) ) ; } }
Find the larger exponential among two exponentials | C # implementation of the approach ; Function to find whether a ^ b is greater or c ^ d ; Find b * log ( a ) ; Find d * log ( c ) ; Compare both values ; Driver code
using System ; class GFG { static void compareValues ( int a , int b , int c , int d ) { double log1 = Math . Log10 ( a ) ; double num1 = log1 * b ; double log2 = Math . Log10 ( c ) ; double num2 = log2 * d ; if ( num1 > num2 ) Console . WriteLine ( a + " ^ " + b ) ; else Console . WriteLine ( c + " ^ " + d ) ; } public static void Main ( ) { int a = 8 , b = 29 , c = 60 , d = 59 ; compareValues ( a , b , c , d ) ; } }
Sum of prime numbers without odd prime digits | C # program for above approach ; Find all prime numbers ; Store all prime numbers ; Function to check if a digit is odd prime or not ; Function to find sum ; To store required answer ; Get all prime numbers ; Traverse through all the prime numbers ; Flag stores 1 if a number does not contain any odd primes ; Find all digits of a number ; If number does not contain any odd primes ; Return the required answer ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static int MAX = 100005 ; static List < int > addPrimes ( ) { int n = MAX ; Boolean [ ] prime = new Boolean [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } List < int > ans = new List < int > ( ) ; for ( int p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) ans . Add ( p ) ; return ans ; } static Boolean is_prime ( int n ) { return ( n == 3 n == 5 n == 7 ) ; } static int find_Sum ( int n ) { int sum = 0 ; List < int > v = addPrimes ( ) ; for ( int i = 0 ; i < v . Count && n > 0 ; i ++ ) { int flag = 1 ; int a = v [ i ] ; while ( a != 0 ) { int d = a % 10 ; a = a / 10 ; if ( is_prime ( d ) ) { flag = 0 ; break ; } } if ( flag == 1 ) { n -- ; sum = sum + v [ i ] ; } } return sum ; } public static void Main ( String [ ] args ) { int n = 7 ; Console . WriteLine ( find_Sum ( n ) ) ; } }
Count the number of primes in the prefix sum array of the given array | C # implementation of the approach ; returns the max element ; Function to return the count of primes in the given array ; Find maximum value in the array ; USE SIEVE TO FIND ALL PRIME NUMBERS LESS THAN OR EQUAL TO max_val Create a bool array " prime [ 0 . . n ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; Remaining part of SIEVE ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Find all primes in arr [ ] ; Function to generate the prefix array ; Fill the prefix array ; Driver code ; Prefix array of arr [ ] ; Count of primes in the prefix array
using System ; class GFG { static int max_element ( int [ ] a ) { int m = a [ 0 ] ; for ( int i = 0 ; i < a . Length ; i ++ ) m = Math . Max ( a [ i ] , m ) ; return m ; } static int primeCount ( int [ ] arr , int n ) { int max_val = max_element ( arr ) ; bool [ ] prime = new bool [ max_val + 1 ] ; for ( int p = 0 ; p <= max_val ; p ++ ) prime [ p ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( prime [ arr [ i ] ] ) count ++ ; return count ; } static int [ ] getPrefixArray ( int [ ] arr , int n , int [ ] pre ) { pre [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { pre [ i ] = pre [ i - 1 ] + arr [ i ] ; } return pre ; } public static void Main ( ) { int [ ] arr = { 1 , 4 , 8 , 4 } ; int n = arr . Length ; int [ ] pre = new int [ n ] ; pre = getPrefixArray ( arr , n , pre ) ; Console . Write ( primeCount ( pre , n ) ) ; } }
Minimum value to be added to X such that it is at least Y percent of N | C # implementation of the approach ; Function to return the required value that must be added to x so that it is at least y percent of n ; Required value ; If x is already >= y percent of n ; Driver code
using System ; class GFG { static int minValue ( int n , int x , int y ) { float val = ( y * n ) / 100 ; if ( x >= val ) return 0 ; else return ( int ) ( Math . Ceiling ( val ) - x ) ; } public static void Main ( ) { int n = 10 , x = 2 , y = 40 ; Console . WriteLine ( ( int ) minValue ( n , x , y ) ) ; } }
Check if N is a Factorial Prime | C # program to check if given number is a factorial prime ; Utility function to check if a number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function that returns true if n is a factorial prime ; If n is not prime then return false ; Calculate factorial ; If n is a factorial prime ; n is not a factorial prime ; Driver code
using System ; class GFG { static bool isPrime ( long n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static bool isFactorialPrime ( long n ) { if ( ! isPrime ( n ) ) return false ; long fact = 1 ; int i = 1 ; while ( fact <= n + 1 ) { fact = fact * i ; if ( n + 1 == fact n - 1 == fact ) return true ; i ++ ; } return false ; } public static void Main ( ) { int n = 23 ; if ( isFactorialPrime ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Seating arrangement of n boys and girls alternatively around a round table | C # program to find number of ways in which n boys and n girls can sit alternatively sound a round table . ; Get n ; find fac1 = ( n - 1 ) ! ; Find fac2 = n ! ; Find total number of ways ; Print the total number of ways
using System ; class GFG { long n = 5 ; long fac1 = 1 ; for ( int i = 2 ; i < = n - 1 ; ++ ) fac1 = fac1 * i ; long fac2 = fac1 * n ; long totalWays = fac1 * fac2 ; Console . WriteLine ( totalWays ) ; } }
Check whether the given number is Euclid Number or not | C # program to check Euclid Number ; Function to get the prime numbers ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; store all prime numbers to vector ' arr ' ; Function to check the number for Euclid Number ; Multiply next prime number and check if product + 1 = n holds or not ; Driver code ; Get the prime numbers ; Get n ; Check if n is Euclid Number ; Get n ; Check if n is Euclid Number
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 10000 ; static List < int > arr = new List < int > ( ) ; static void SieveOfEratosthenes ( ) { bool [ ] prime = new bool [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) prime [ i ] = 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 ; } } for ( int p = 2 ; p < MAX ; p ++ ) if ( prime [ p ] ) arr . Add ( p ) ; } static bool isEuclid ( long n ) { long product = 1 ; int i = 0 ; while ( product < n ) { product = product * arr [ i ] ; if ( product + 1 == n ) return true ; i ++ ; } return false ; } public static void Main ( String [ ] args ) { SieveOfEratosthenes ( ) ; long n = 31 ; if ( isEuclid ( n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; n = 42 ; if ( isEuclid ( n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Perfect cube greater than a given number | C # implementation of above approach ; Function to find the next perfect cube ; Driver Code
using System ; class GFG { static int nextPerfectCube ( int N ) { int nextN = ( int ) Math . Floor ( Math . Pow ( N , ( double ) 1 / 3 ) ) + 1 ; return nextN * nextN * nextN ; } public static void Main ( ) { int n = 35 ; Console . Write ( nextPerfectCube ( n ) ) ; } }
Sum of all the prime divisors of a number | C # program to find sum of prime divisors of N ; Function to check if the number is prime or not . ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; function to find sum of prime divisors of N ; return type of sqrt function if float ; both factors are same ; both factors are not same ( i and n / i ) ; Driver code
using System ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static int SumOfPrimeDivisors ( int n ) { int sum = 0 ; int root_n = ( int ) Math . Sqrt ( n ) ; for ( int i = 1 ; i <= root_n ; i ++ ) { if ( n % i == 0 ) { if ( i == n / i && isPrime ( i ) ) { sum += i ; } else { if ( isPrime ( i ) ) { sum += i ; } if ( isPrime ( n / i ) ) { sum += ( n / i ) ; } } } } return sum ; } static void Main ( ) { int n = 60 ; Console . WriteLine ( " Sum ▁ of ▁ prime ▁ divisors ▁ of ▁ 60 ▁ is ▁ " + SumOfPrimeDivisors ( n ) ) ; } }
Position of n among the numbers made of 2 , 3 , 5 & 7 | C # Program position of n among the numbers made of 2 , 3 , 5 & 7 ; If number is 2 then it is on the position pos * 2 + 1 ; If number is 3 then it is on the position pos * 2 + 2 ; If number is 5 then it is on the position pos * 2 + 3 ; If number is 7 then it is on the position pos * 2 + 4 ; Driver code
using System ; class GFG { static int findpos ( String n ) { int pos = 0 ; for ( int i = 0 ; i < n . Length ; i ++ ) { switch ( n [ i ] ) { case '2' : pos = pos * 4 + 1 ; break ; case '3' : pos = pos * 4 + 2 ; break ; case '5' : pos = pos * 4 + 3 ; break ; case '7' : pos = pos * 4 + 4 ; break ; } } return pos ; } public static void Main ( String [ ] args ) { String n = "777" ; Console . WriteLine ( findpos ( n ) ) ; } }
Finding a Non Transitive Co | C # program to find a non transitive co - prime triplets between L and R ; Checks if any possible triplet ( a , b , c ) satifying the condition that ( a , b ) is coprime , ( b , c ) is coprime but ( a , c ) isnt ; Case 1 : Less than 3 numbers between L and R ; Case 2 : More than 3 numbers between L and R ; triplets should always be of form ( 2 k , 2 k + 1 , 2 k + 2 ) ; Case 3.1 : Exactly 3 numbers in range of form ( 2 k , 2 k + 1 , 2 k + 2 ) ; Case 3.2 : Exactly 3 numbers in range of form ( 2 k - 1 , 2 k , 2 k + 1 ) ; flag = True indicates that a pair exists between L and R ; Driver code ; finding possible Triplet between 2 and 10 ; finding possible Triplet between 23 and 46
using System ; public class GFG { static void possibleTripletInRange ( int L , int R ) { bool flag = false ; int possibleA = 0 , possibleB = 0 , possibleC = 0 ; int numbersInRange = ( R - L + 1 ) ; if ( numbersInRange < 3 ) { flag = false ; } else if ( numbersInRange > 3 ) { flag = true ; if ( L % 2 > 0 ) { L ++ ; } possibleA = L ; possibleB = L + 1 ; possibleC = L + 2 ; } else { if ( ! ( L % 2 > 0 ) ) { flag = true ; possibleA = L ; possibleB = L + 1 ; possibleC = L + 2 ; } else { flag = false ; } } if ( flag == true ) { Console . WriteLine ( " ( " + possibleA + " , ▁ " + possibleB + " , ▁ " + possibleC + " ) " + " ▁ is ▁ one ▁ such ▁ possible " + " ▁ triplet ▁ between ▁ " + L + " ▁ and ▁ " + R ) ; } else { Console . WriteLine ( " No ▁ Such ▁ Triplet " + " ▁ exists ▁ between ▁ " + L + " ▁ and ▁ " + R ) ; } } static public void Main ( ) { int L , R ; L = 2 ; R = 10 ; possibleTripletInRange ( L , R ) ; L = 23 ; R = 46 ; possibleTripletInRange ( L , R ) ; } }
Count n digit numbers not having a particular digit | C # Implementation of above method ; Finding number of possible number with n digits excluding a particular digit ; Checking if number of digits is zero ; Checking if number of digits is one ; Checking if number of digits is odd ; Calling digitNumber function with ( digit - 1 ) / 2 digits ; Calling digitNumber function with n / 2 digits ; Calling digitNumber function Checking if excluding digit is zero or non - zero ; Driver function to run above program ; Initializing variables
using System ; class GFG { static int mod = 1000000007 ; static int digitNumber ( long n ) { if ( n == 0 ) return 1 ; if ( n == 1 ) return 9 ; if ( n % 2 != 0 ) { int temp = digitNumber ( ( n - 1 ) / 2 ) % mod ; return ( 9 * ( temp * temp ) % mod ) % mod ; } else { int temp = digitNumber ( n / 2 ) % mod ; return ( temp * temp ) % mod ; } } static int countExcluding ( int n , int d ) { if ( d == 0 ) return ( 9 * digitNumber ( n - 1 ) ) % mod ; else return ( 8 * digitNumber ( n - 1 ) ) % mod ; } public static void Main ( ) { int d = 9 ; int n = 3 ; Console . WriteLine ( countExcluding ( n , d ) ) ; } }
Check if given number is Emirp Number or not | C # program to check if given number is Emirp or not . ; Returns true if n is prime Else false . ; Corner case ; Check from 2 to n - 1 ; Function will check whether number is Emirp or not ; Check if n is prime ; Find reverse of n ; If both Original and Reverse are Prime , then it is an Emirp number ; Driver Function ; Input number
using System ; class Emirp { public static bool isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } public static bool isEmirp ( int n ) { if ( isPrime ( n ) == false ) return false ; int rev = 0 ; while ( n != 0 ) { int d = n % 10 ; rev = rev * 10 + d ; n /= 10 ; } return isPrime ( rev ) ; } public static void Main ( ) { int n = 13 ; if ( isEmirp ( n ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Program to Convert Radian to Degree | C # code to convert radian to degree . ; Function for convertion ; Driver Code
using System ; class GFG { static double Convert ( double radian ) { double pi = 3.14159 ; return ( radian * ( 180 / pi ) ) ; } public static void Main ( ) { double radian = 5.0 ; double degree = Convert ( radian ) ; Console . Write ( " degree ▁ = ▁ " + degree ) ; } }
Find trace of matrix formed by adding Row | C # program to find trace of matrix formed by adding Row - major and Column - major order of same matrix ; Return sum of first n integers of an AP ; Return the trace of sum of row - major matrix and column - major matrix ; Finding nth element in AP in case of Row major matrix . ; Finding sum of first n integers of AP in case of Row major matrix ; Finding nth element in AP in case of Row major matrix ; Finding sum of first n integers of AP in case of Column major matrix ; Driven Program
using System ; public class GFG { static int sn ( int n , int an ) { return ( n * ( 1 + an ) ) / 2 ; } static int trace ( int n , int m ) { int an = 1 + ( n - 1 ) * ( m + 1 ) ; int rowmajorSum = sn ( n , an ) ; an = 1 + ( n - 1 ) * ( n + 1 ) ; int colmajorSum = sn ( n , an ) ; return rowmajorSum + colmajorSum ; } static public void Main ( ) { int N = 3 , M = 3 ; Console . WriteLine ( trace ( N , M ) ) ; } }
Maximum of smallest possible area that can get with exactly k cut of given rectangular | C # code for Maximum of smallest possible area that can get with exactly k cut of given rectangular ; Utility Function ; for the 1 st case ; for the second case ; print final result ; Driver code
using System ; class GFG { static void max_area ( int n , int m , int k ) { if ( k > ( n + m - 2 ) ) Console . WriteLine ( " Not ▁ possible " ) ; else { int result ; if ( k < Math . Max ( m , n ) - 1 ) { result = Math . Max ( m * ( n / ( k + 1 ) ) , n * ( m / ( k + 1 ) ) ) ; } else { result = Math . Max ( m / ( k - n + 2 ) , n / ( k - m + 2 ) ) ; } Console . WriteLine ( result ) ; } } public static void Main ( ) { int n = 3 , m = 4 , k = 1 ; max_area ( n , m , k ) ; } }
Program to find the area of a Square | C # program to find the area of a square ; function to find the area ; Driver code
using System ; class GFG { static int area_fun ( int side ) { int area = side * side ; return area ; } public static void Main ( ) { int side = 4 ; int area = area_fun ( side ) ; Console . WriteLine ( area ) ; } }
Count ways to express a number as sum of consecutive numbers | A C # program to count number of ways to express N as sum of consecutive numbers . ; Utility method to compute number of ways in which N can be represented as sum of consecutive number ; constraint on values of L gives us the time Complexity as O ( N ^ 0.5 ) ; Driver code to test above function
using System ; public class GFG { static int countConsecutive ( int N ) { int count = 0 ; for ( int L = 1 ; L * ( L + 1 ) < 2 * N ; L ++ ) { double a = ( double ) ( ( 1.0 * N - ( L * ( L + 1 ) ) / 2 ) / ( L + 1 ) ) ; if ( a - ( int ) a == 0.0 ) count ++ ; } return count ; } public static void Main ( ) { int N = 15 ; Console . WriteLine ( countConsecutive ( N ) ) ; N = 10 ; Console . Write ( countConsecutive ( N ) ) ; } }
Automorphic Number | C # program to check if a number is Authomorphic ; Function to check Automorphic number ; Store the square ; Start Comparing digits ; Return false , if any digit of N doesn ' t ▁ match ▁ with ▁ its ▁ ▁ square ' s digits from last ; Reduce N and square ; Driver Code
using System ; class GFG { static bool isAutomorphic ( int N ) { int sq = N * N ; while ( N > 0 ) { if ( N % 10 != sq % 10 ) return false ; N /= 10 ; sq /= 10 ; } return true ; } public static void Main ( ) { int N = 5 ; Console . Write ( isAutomorphic ( N ) ? " Automorphic " : " Not ▁ Automorphic " ) ; } }