codeparrot/xlcost-text-to-code huggingface dataset:
Product of all the pairs from the given array | C # implementation to find the product of all the pairs from the given array ; Function to return the product of the elements of all possible pairs from the array ; To store the required product ; Nested loop to calculate all possible pairs ; Multiply the product of the elements of the current pair ; Return the readonly result ; Driver code
using System ; class GFG { static readonly int mod = 1000000007 ; static int productPairs ( int [ ] arr , int n ) { int product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { product *= ( arr [ i ] % mod * arr [ j ] % mod ) % mod ; product = product % mod ; } } return product % mod ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 } ; int n = arr . Length ; Console . Write ( productPairs ( arr , n ) ) ; } }
Product of all the pairs from the given array | C # implementation to Find the product of all the pairs from the given array ; Function to calculate ( x ^ y ) % 1000000007 ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; Return the final result ; Function to return the product of the elements of all possible pairs from the array ; To store the required product ; Iterate for every element of the array ; Each element appears ( 2 * n ) times ; Driver code
using System ; class GFG { const int mod = 1000000007 ; static int power ( int x , int y ) { int p = 1000000007 ; int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static int productPairs ( int [ ] arr , int n ) { int product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { product = ( product % mod * ( int ) power ( arr [ i ] , ( 2 * n ) ) % mod ) % mod ; } return product % mod ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 } ; int n = arr . Length ; Console . Write ( productPairs ( arr , n ) ) ; } }
Construct an Array such that cube sum of all element is a perfect square | C # program to construct array that cube sum of all element is a perfect square ; Function to create and print the array ; Initialise the array of size N ; Print the array ; Driver code
using System ; class GFG { static void constructArray ( int N ) { int [ ] arr = new int [ N ] ; for ( int i = 1 ; i <= N ; i ++ ) { arr [ i - 1 ] = i ; } for ( int i = 0 ; i < N ; i ++ ) { Console . Write ( arr [ i ] + " , ▁ " ) ; } } public static void Main ( ) { int N = 6 ; constructArray ( N ) ; } }
Count of all subsequence whose product is a Composite number | C # implementation to count all subsequence whose product is Composite number ; Function to check whether a number is prime or not ; Function to find number of subsequences whose product is a composite number ; Find total non empty subsequence ; Find count of prime number and ones ; Calculate the non empty one subsequence ; Find count of composite subsequence ; Driver code
using System ; class GFG { 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 ; } static int countSubsequences ( int [ ] arr , int n ) { int totalSubsequence = ( int ) ( Math . Pow ( 2 , n ) - 1 ) ; int countPrime = 0 , countOnes = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) countOnes ++ ; else if ( isPrime ( arr [ i ] ) ) countPrime ++ ; } int compositeSubsequence ; int onesSequence = ( int ) ( Math . Pow ( 2 , countOnes ) - 1 ) ; compositeSubsequence = totalSubsequence - countPrime - onesSequence - onesSequence * countPrime ; return compositeSubsequence ; } public static void Main ( ) { int [ ] arr = { 2 , 1 , 2 } ; int n = arr . Length ; Console . Write ( countSubsequences ( arr , n ) ) ; } }
Find K consecutive integers such that their sum is N | C # implementation to check if a number can be expressed as sum of K consecutive integer ; Function to check if a number can be expressed as the sum of k consecutive ; Finding the first term of AP ; Checking if first term is an integer ; Loop to print the K consecutive integers ; Driver Code
using System ; class GFG { static void checksum ( int n , int k ) { float first_term = ( float ) ( ( ( 2 * n ) / k + ( 1 - k ) ) / 2.0 ) ; if ( first_term - ( int ) ( first_term ) == 0 ) { for ( int i = ( int ) first_term ; i <= first_term + k - 1 ; i ++ ) { Console . Write ( i + " ▁ " ) ; } } else Console . Write ( " - 1" ) ; } public static void Main ( String [ ] args ) { int n = 33 , k = 6 ; checksum ( n , k ) ; } }
Represent N as sum of K even numbers | C # implementation to represent N as sum of K even numbers ; Function to print the representation ; N must be greater than equal to 2 * K and must be even ; Driver Code
using System ; class GFG { static void sumEvenNumbers ( int N , int K ) { int check = N - 2 * ( K - 1 ) ; if ( check > 0 && check % 2 == 0 ) { for ( int i = 0 ; i < K - 1 ; i ++ ) { Console . Write ( "2 ▁ " ) ; } Console . WriteLine ( check ) ; } else { Console . WriteLine ( " - 1" ) ; } } static public void Main ( String [ ] args ) { int N = 8 ; int K = 2 ; sumEvenNumbers ( N , K ) ; } }
Count of contiguous subarrays possible for every index by including the element at that index | C # program to find the number of contiguous subarrays including the element at every index of the array of size N ; Function to find the number of subarrays including the element at every index of the array ; Creating an array of size N ; The loop is iterated till half the length of the array ; Condition to avoid overwriting the middle element for the array with even length . ; Computing the number of subarrays ; The ith element from the beginning and the ending have the same number of possible subarray ; Function to print the vector ; Driver code
using System ; class GFG { public static int [ ] calculateWays ( int N ) { int x = 0 ; int [ ] v = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) v [ i ] = 0 ; for ( int i = 0 ; i < N / 2 ; i ++ ) { if ( N % 2 == 0 && i == N / 2 ) break ; x = N * ( i + 1 ) - ( i + 1 ) * i ; v [ i ] = x ; v [ N - i - 1 ] = x ; } return v ; } public static void printArray ( int [ ] v ) { for ( int i = 0 ; i < v . Length ; i ++ ) { Console . Write ( v [ i ] + " ▁ " ) ; } } public static void Main ( string [ ] args ) { int [ ] v ; v = calculateWays ( 4 ) ; printArray ( v ) ; } }
Smallest number greater than or equal to X whose sum of digits is divisible by Y | C # program to find the smallest number greater than or equal to X and divisible by Y ; Function that returns the sum of digits of a number ; Initialize variable to store the sum ; Add the last digit of the number ; Remove the last digit from the number ; Function that returns the smallest number greater than or equal to X and divisible by Y ; Initialize result variable ; Loop through numbers greater than equal to X ; Calculate sum of digits ; Check if sum of digits is divisible by Y ; Driver code
using System ; class GFG { static readonly int MAXN = 10000000 ; static int sumOfDigits ( int n ) { int sum = 0 ; while ( n > 0 ) { sum += n % 10 ; n /= 10 ; } return sum ; } static int smallestNum ( int X , int Y ) { int res = - 1 ; for ( int i = X ; i < MAXN ; i ++ ) { int sum_of_digit = sumOfDigits ( i ) ; if ( sum_of_digit % Y == 0 ) { res = i ; break ; } } return res ; } public static void Main ( String [ ] args ) { int X = 5923 , Y = 13 ; Console . Write ( smallestNum ( X , Y ) ) ; } }
Count the numbers which can convert N to 1 using given operation | C # program to count the numbers which can convert N to 1 using the given operation ; Function to count the numbers which can convert N to 1 using the given operation ; Store all the divisors of N ; If i is a divisor ; If i is not equal to N / i ; Iterate through all the divisors of N - 1 and count them in answer ; Check if N - 1 is a divisor or not ; Iterate through all divisors and check for N mod d = 1 or ( N - 1 ) mod d = 0 ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int countValues ( int N ) { List < int > div = new List < int > ( ) ; for ( int i = 2 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { div . Add ( i ) ; if ( N != i * i ) { div . Add ( N / i ) ; } } } int answer = 0 ; for ( int i = 1 ; i * i <= N - 1 ; i ++ ) { if ( ( N - 1 ) % i == 0 ) { if ( i * i == N - 1 ) answer ++ ; else answer += 2 ; } } foreach ( int d in div ) { int K = N ; while ( K % d == 0 ) K /= d ; if ( ( K - 1 ) % d == 0 ) answer ++ ; } return answer ; } public static void Main ( String [ ] args ) { int N = 6 ; Console . Write ( countValues ( N ) ) ; } }
Maximum possible prime divisors that can exist in numbers having exactly N divisors | C # implementation to find the maximum possible prime divisor of a number can have N divisors ; Function to find the maximum possible prime divisors of a number can have with N divisors ; Number of time number divided by 2 ; Divide by other prime numbers ; If the last number of also prime then also include it ; Driver Code ; Function Call
using System ; class GFG { static void findMaxPrimeDivisor ( int n ) { int max_possible_prime = 0 ; while ( n % 2 == 0 ) { max_possible_prime ++ ; n = n / 2 ; } for ( int i = 3 ; i * i <= n ; i = i + 2 ) { while ( n % i == 0 ) { max_possible_prime ++ ; n = n / i ; } } if ( n > 2 ) { max_possible_prime ++ ; } Console . Write ( max_possible_prime + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int n = 4 ; findMaxPrimeDivisor ( n ) ; } }
Count ways to express a number as sum of exactly two numbers | C # program to count ways to express a number as sum of two numbers . ; Function returns the count of ways express a number as sum of two numbers . ; Driver code
using System ; class GFG { static int CountWays ( int n ) { int ans = ( n - 1 ) / 2 ; return ans ; } public static void Main ( ) { int N = 8 ; Console . Write ( CountWays ( N ) ) ; } }
Divide array in two maximum equal length arrays of similar and dissimilar elements | C # program to find the max - size to which an array can be divided into 2 equal parts such that one part contains unique elements while another contains similar elements ; Function to find the max - size to which an array can be divided into 2 equal parts ; Array to find the frequency of each element of array ; Find the index maximum frequency element present in array arr [ ] ; Find total unique elements present in array arr [ ] ; Find the Max - Size to which an array arr [ ] can be splitted ; Find the first array containing same elements ; Find the second array containing unique elements ; Driver Code ; Initialise n ; Array declaration ; Size of array
using System ; class GFG { static void Solve ( int [ ] arr , int size , int n ) { int [ ] v = new int [ n + 1 ] ; for ( int i = 0 ; i < size ; i ++ ) v [ arr [ i ] ] ++ ; int max1 = - 1 , mx = - 1 ; for ( int i = 0 ; i < v . Length ; i ++ ) { if ( v [ i ] > mx ) { mx = v [ i ] ; max1 = i ; } } int cnt = 0 ; foreach ( int i in v ) { if ( i == 0 ) ++ cnt ; } int diff1 = n + 1 - cnt ; int max_size = Math . Max ( Math . Min ( v [ max1 ] - 1 , diff1 ) , Math . Min ( v [ max1 ] , diff1 - 1 ) ) ; Console . Write ( " Maximum ▁ size ▁ is ▁ : " + max_size + " STRNEWLINE " ) ; Console . Write ( " The ▁ First ▁ Array ▁ Is ▁ : STRNEWLINE " ) ; for ( int i = 0 ; i < max_size ; i ++ ) { Console . Write ( max1 + " ▁ " ) ; v [ max1 ] -= 1 ; } Console . Write ( " STRNEWLINE " ) ; Console . Write ( " The ▁ Second ▁ Array ▁ Is ▁ : STRNEWLINE " ) ; for ( int i = 0 ; i < ( n + 1 ) ; i ++ ) { if ( v [ i ] > 0 ) { Console . Write ( i + " ▁ " ) ; max_size -- ; } if ( max_size < 1 ) break ; } Console . Write ( " STRNEWLINE " ) ; } public static void Main ( string [ ] args ) { int n = 7 ; int [ ] arr = new int [ ] { 1 , 2 , 1 , 5 , 1 , 6 , 7 , 2 } ; int size = arr . Length ; Solve ( arr , size , n ) ; } }
Find sum of xor of all unordered triplets of the array | C # program to find sum of xor of all unordered triplets of the array ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Returns n ^ ( - 1 ) mod p ; Returns nCr % p using Fermat 's little theorem. ; Base case ; Fill factorial array so that we can find all factorial of r , n and n - r ; Function returns sum of xor of all unordered triplets of the array ; Iterating over the bits ; Number of elements whith k 'th bit  1 and 0 respectively ; Checking if k 'th bit is 1 ; Adding this bit 's part to the answer ; Driver code
using System ; class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } static int modInverse ( int n , int p ) { return power ( n , p - 2 , p ) ; } static int nCrModPFermat ( int n , int r , int p ) { if ( r == 0 ) return 1 ; if ( n < r ) return 0 ; int [ ] fac = new int [ n + 1 ] ; fac [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) fac [ i ] = fac [ i - 1 ] * i % p ; return ( fac [ n ] * modInverse ( fac [ r ] , p ) % p * modInverse ( fac [ n - r ] , p ) % p ) % p ; } static int SumOfXor ( int [ ] a , int n ) { int mod = 10037 ; int answer = 0 ; for ( int k = 0 ; k < 32 ; k ++ ) { int x = 0 , y = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( a [ i ] & ( 1 << k ) ) != 0 ) x ++ ; else y ++ ; } answer += ( ( 1 << k ) % mod * ( nCrModPFermat ( x , 3 , mod ) + x * nCrModPFermat ( y , 2 , mod ) ) % mod ) % mod ; } return answer ; } public static void Main ( String [ ] args ) { int n = 5 ; int [ ] A = { 3 , 5 , 2 , 18 , 7 } ; Console . WriteLine ( SumOfXor ( A , n ) ) ; } }
Probability of not getting two consecutive heads together in N tosses of coin | C # implementation to find the probability of not getting two consecutive heads together when N coins are tossed ; Function to compute the N - th Fibonacci number in the sequence where a = 2 and b = 3 ; The first two numbers in the sequence are initialized ; Base cases ; Loop to compute the fibonacci sequence based on the first two initialized numbers ; Function to find the probability of not getting two consecutive heads when N coins are tossed ; Computing the number of favourable cases ; Computing the number of all possible outcomes for N tosses ; Driver code
using System ; class GFG { public static float round ( float var , int digit ) { float value = ( int ) ( var * Math . ( 10 , digit ) + .5 ) ; return ( float ) value / ( float ) Math . Pow ( 10 , digit ) ; } public static int probability ( int N ) { int a = 2 ; int b = 3 ; if ( N == 1 ) { return a ; } else if ( N == 2 ) { return b ; } else { for ( int i = 3 ; i <= N ; i ++ ) { int c = a + b ; a = b ; b = c ; } return b ; } } public static float operations ( int N ) { int x = probability ( N ) ; int y = ( int ) Math . Pow ( 2 , N ) ; return round ( ( float ) x / ( float ) y , 2 ) ; } public static void Main ( string [ ] args ) { int N = 10 ; Console . WriteLine ( ( operations ( N ) ) ) ; } }
Check if number formed by joining two Numbers is Perfect Cube | C # program to check if the concatenation of two numbers is a perfect cube or not ; Function to check if a number is a perfect Cube or not ; Function to check if concatenation of two numbers is a perfect cube or not ; Convert numbers to string using to_string ( ) ; Concatenate the numbers and convert it into integer ; Check if concatenated value is perfect cube or not ; Driver Code
using System ; class GFG { static bool isPerfectCube ( int x ) { double cr = Math . Round ( Math . Cbrt ( x ) ) ; return ( cr * cr * cr == x ) ; } static void checkCube ( int a , int b ) { string s1 = Convert . ToString ( a ) ; string s2 = Convert . ToString ( b ) ; int c = Convert . ToInt32 ( s1 + s2 ) ; if ( isPerfectCube ( c ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } public static void Main ( ) { int a = 6 ; int b = 4 ; checkCube ( a , b ) ; } }
Largest number in given Array formed by repeatedly combining two same elements | C # implementation of the above approach ; Function to return the largest sum ; Variable to store the largest sum ; Map to store the frequencies of each element ; Store the Frequencies ; Loop to combine duplicate elements and update the sum in the map ; If j is a duplicate element Console . Write ( m [ arr [ i ] ] ) ; ; Update the frequency of 2 * j ; If the new sum is greater than maximum value , Update the maximum ; Returns the largest sum ; Driver Code ; Function Calling
using System ; using System . Collections . Generic ; class GFG { static int largest_sum ( int [ ] arr , int n ) { int maximum = - 1 ; Dictionary < int , int > m = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . ContainsKey ( arr [ i ] ) ) { m [ arr [ i ] ] ++ ; } else { m . Add ( arr [ i ] , 1 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( m [ arr [ i ] ] > 1 ) { if ( m . ContainsKey ( 2 * arr [ i ] ) ) { m [ 2 * arr [ i ] ] = m [ 2 * arr [ i ] ] + m [ arr [ i ] ] / 2 ; } else { m . Add ( 2 * arr [ i ] , m [ arr [ i ] ] / 2 ) ; } if ( 2 * arr [ i ] > maximum ) maximum = 2 * arr [ i ] ; } } return maximum ; } public static void Main ( ) { int [ ] arr = { 1 , 1 , 2 , 4 , 7 , 8 } ; int n = arr . Length ; Console . Write ( largest_sum ( arr , n ) ) ; } }
Check if it is possible to make x and y zero at same time with given operation | C # program of the above approach ; Function to check if it is possible to make x and y can become 0 at same time ; Check the given conditions ; Driver Code ; Function Call
using System ; class GFG { static void canBeReduced ( int x , int y ) { int maxi = Math . Max ( x , y ) ; int mini = Math . Min ( x , y ) ; if ( ( ( x + y ) % 3 ) == 0 && maxi <= 2 * mini ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } static void Main ( ) { int x = 6 , y = 9 ; canBeReduced ( x , y ) ; } }
Wheel Factorization Algorithm | C # program to check if the given number is prime using Wheel Factorization Method ; Function to check if a given number x is prime or not ; The Wheel for checking prime number ; Base Case ; Check for the number taken as basis ; Check for Wheel Here i , acts as the layer of the wheel ; Check for the list of Sieve in arr [ ] ; If number is greater than sqrt ( N ) break ; Check if N is a multiple of prime number in the wheel ; If at any iteration isPrime is false , break from the loop ; Driver 's Code ; Function call for primality check
using System ; class GFG { static void isPrime ( int N ) { bool isPrime = true ; int [ ] arr = { 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 } ; if ( N < 2 ) { isPrime = false ; } if ( N % 2 == 0 N % 3 == 0 N % 5 == 0 ) { isPrime = false ; } for ( int i = 0 ; i < ( int ) Math . Sqrt ( N ) ; i += 30 ) { foreach ( int c in arr ) { if ( c > ( int ) Math . Sqrt ( N ) ) { break ; } else { if ( N % ( c + i ) == 0 ) { isPrime = false ; break ; } } if ( ! isPrime ) break ; } } if ( isPrime ) Console . WriteLine ( " Prime ▁ Number " ) ; else Console . WriteLine ( " Not ▁ a ▁ Prime ▁ Number " ) ; } public static void Main ( String [ ] args ) { int N = 121 ; isPrime ( N ) ; } }
Find all Pairs possible from the given Array | C # implementation to find all Pairs possible from the given Array ; Function to print all possible pairs from the array ; Nested loop for all possible pairs ; Driver code
using System ; class GFG { static void printPairs ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { Console . Write ( " ( " + arr [ i ] + " , ▁ " + arr [ j ] + " ) " + " , ▁ " ) ; } } } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 2 } ; int n = arr . Length ; printPairs ( arr , n ) ; } }
Check if a circle lies inside another circle or not | C # program to check if one circle lies inside another circle or not . ; Driver code
using System ; class GFG { static void circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) { int distSq = ( int ) Math . Sqrt ( ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) ) ; if ( distSq + r2 == r1 ) { Console . WriteLine ( " The ▁ smaller ▁ circle ▁ lies ▁ completely " + " ▁ inside ▁ the ▁ bigger ▁ circle ▁ with ▁ " + " touching ▁ each ▁ other ▁ " + " at ▁ a ▁ point ▁ of ▁ circumference . ▁ " ) ; } else if ( distSq + r2 < r1 ) { Console . WriteLine ( " The ▁ smaller ▁ circle ▁ lies ▁ completely " + " ▁ inside ▁ the ▁ bigger ▁ circle ▁ without " + " ▁ touching ▁ each ▁ other ▁ " + " at ▁ a ▁ point ▁ of ▁ circumference . " ) ; } else { Console . WriteLine ( " The ▁ smaller ▁ does ▁ not ▁ lies ▁ inside " + " ▁ the ▁ bigger ▁ circle ▁ completely . " ) ; } } static public void Main ( ) { int x1 = 10 , y1 = 8 ; int x2 = 1 , y2 = 2 ; int r1 = 30 , r2 = 10 ; circle ( x1 , y1 , x2 , y2 , r1 , r2 ) ; } }
Length of direct common tangent between two intersecting Circles | C # program to find the length of the direct common tangent between two circles which intersect each other ; Function to find the length of the direct common tangent ; Driver code
using System ; class GFG { static void lengtang ( double r1 , double r2 , double d ) { Console . WriteLine ( " The ▁ length ▁ of ▁ the ▁ direct " + " ▁ common ▁ tangent ▁ is ▁ " + ( Math . Sqrt ( Math . Pow ( d , 2 ) - Math . Pow ( ( r1 - r2 ) , 2 ) ) ) ) ; } public static void Main ( String [ ] args ) { double r1 = 4 , r2 = 6 , d = 3 ; lengtang ( r1 , r2 , d ) ; } }
Radius of the circle when the width and height of an arc is given | C # program to find radius of the circle when the width and height of an arc is given ; Function to find the radius ; Driver code
using System ; class GFG { static void rad ( double d , double h ) { Console . WriteLine ( " The ▁ radius ▁ of ▁ the ▁ circle ▁ is ▁ " + ( ( d * d ) / ( 8 * h ) + h / 2 ) ) ; } public static void Main ( ) { double d = 4 , h = 1 ; rad ( d , h ) ; } }
Shortest distance from the centre of a circle to a chord | C # program to find the shortest distance from chord to the centre of circle ; Function to find the shortest distance ; Driver code
using System ; class GFG { static void shortdis ( double r , double d ) { Console . WriteLine ( " The ▁ shortest ▁ distance ▁ " + " from ▁ the ▁ chord ▁ to ▁ centre ▁ " + ( Math . Sqrt ( ( r * r ) - ( ( d * d ) / 4 ) ) ) ) ; } public static void Main ( ) { double r = 4 , d = 3 ; shortdis ( r , d ) ; } }
Length of direct common tangent between the two non | C # program to find the length of the direct common tangent between two circles which donot touch each other ; Function to find the length of the direct common tangent ; Driver code
using System ; class GFG { static void lengtang ( double r1 , double r2 , double d ) { Console . WriteLine ( " The ▁ length ▁ of ▁ the ▁ direct " + " ▁ common ▁ tangent ▁ is ▁ " + ( Math . Sqrt ( Math . Pow ( d , 2 ) - Math . Pow ( ( r1 - r2 ) , 2 ) ) ) ) ; } public static void Main ( ) { double r1 = 4 , r2 = 6 , d = 12 ; lengtang ( r1 , r2 , d ) ; } }
Biggest Square that can be inscribed within an Equilateral triangle | C # Program to find the biggest square which can be inscribed within the equilateral triangle ; Function to find the side of the square ; the side cannot be negative ; side of the square ; Driver code
using System ; class GFG { static double square ( double a ) { if ( a < 0 ) return - 1 ; double x = 0.464 * a ; return x ; } public static void Main ( ) { double a = 5 ; Console . WriteLine ( square ( a ) ) ; } }
Apothem of a n | C # Program to find the apothem of a regular polygon with given side length ; Function to find the apothem of a regular polygon ; Side and side length cannot be negative ; Degree converted to radians ; Driver code
using System ; class GFG { static double polyapothem ( double n , double a ) { if ( a < 0 && n < 0 ) return - 1 ; return ( a / ( 2 * Math . Tan ( ( 180 / n ) * 3.14159 / 180 ) ) ) ; } public static void Main ( ) { double a = 9 , n = 6 ; Console . WriteLine ( Math . Round ( polyapothem ( n , a ) , 4 ) ) ; } }