codeparrot/xlcost-text-to-code huggingface dataset:
Count the nodes in the given tree whose weight is a powerful number | C # implementation to count the nodes in thegiven tree whose weight is a powerful number ; Function to check if the number is powerful ; First divide the number repeatedly by 2 ; Check if only 2 ^ 1 divides n , then return false ; Check if n is not a power of 2 then this loop will execute ; Find highest power of " factor " that divides n ; Check if only factor ^ 1 divides n , then return false ; n must be 1 now if it is not a prime number . Since prime numbers are not powerful , we return false if n is not 1. ; Function to perform dfs ; Check if weight of the current node is a powerful number ; Driver code ; Weights of the node ; Edges of the tree
using System ; using System . Collections . Generic ; class GFG { static int ans = 0 ; static List < int > [ ] graph = new List < int > [ 100 ] ; static int [ ] weight = new int [ 100 ] ; static bool isPowerful ( int n ) { while ( n % 2 == 0 ) { int power = 0 ; while ( n % 2 == 0 ) { n /= 2 ; power ++ ; } if ( power == 1 ) return false ; } for ( int factor = 3 ; factor <= Math . Sqrt ( n ) ; factor += 2 ) { int power = 0 ; while ( n % factor == 0 ) { n = n / factor ; power ++ ; } if ( power == 1 ) return false ; } return ( n == 1 ) ; } static void dfs ( int node , int parent ) { if ( isPowerful ( weight [ node ] ) ) ans += 1 ; foreach ( int to in graph [ node ] ) { if ( to == parent ) continue ; dfs ( to , node ) ; } } public static void Main ( String [ ] args ) { for ( int i = 0 ; i < graph . Length ; i ++ ) graph [ i ] = new List < int > ( ) ; weight [ 1 ] = 5 ; weight [ 2 ] = 10 ; weight [ 3 ] = 11 ; weight [ 4 ] = 8 ; weight [ 5 ] = 6 ; graph [ 1 ] . Add ( 2 ) ; graph [ 2 ] . Add ( 3 ) ; graph [ 2 ] . Add ( 4 ) ; graph [ 1 ] . Add ( 5 ) ; dfs ( 1 , 1 ) ; Console . Write ( ans ) ; } }
Number of ways to color boundary of each block of M * N table | C # program to count the number of ways to color boundary of each block of M * N table . ; Function to compute all way to fill the boundary of all sides of the unit square ; Count possible ways to fill all upper and left side of the rectangle M * N ; Count possible ways to fill all side of the all squares unit size ; Driver code ; Number of rows ; Number of columns
using System ; class GFG { static int CountWays ( int N , int M ) { int count = 1 ; count = ( int ) Math . Pow ( 3 , M + N ) ; count *= ( int ) Math . Pow ( 2 , M * N ) ; return count ; } static void Main ( ) { int N = 3 ; int M = 2 ; Console . Write ( CountWays ( N , M ) ) ; } }
Nth positive number whose absolute difference of adjacent digits is at most 1 | C # program to find Nth number with absolute difference between all adjacent digits at most 1. ; Return Nth number with absolute difference between all adjacent digits at most 1. ; To store all such numbers ; Enqueue all integers from 1 to 9 in increasing order . ; Perform the operation N times so that we can get all such N numbers . ; Store the front element of queue , in array and pop it from queue . ; If the last digit of dequeued integer is not 0 , then enqueue the next such number . ; Enqueue the next such number ; If the last digit of dequeued integer is not 9 , then enqueue the next such number . ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void findNthNumber ( int N ) { int [ ] arr = new int [ N + 1 ] ; Queue < int > q = new Queue < int > ( ) ; for ( int i = 1 ; i <= 9 ; i ++ ) q . Enqueue ( i ) ; for ( int i = 1 ; i <= N ; i ++ ) { arr [ i ] = q . Peek ( ) ; q . Dequeue ( ) ; if ( arr [ i ] % 10 != 0 ) q . Enqueue ( arr [ i ] * 10 + arr [ i ] % 10 - 1 ) ; q . Enqueue ( arr [ i ] * 10 + arr [ i ] % 10 ) ; if ( arr [ i ] % 10 != 9 ) q . Enqueue ( arr [ i ] * 10 + arr [ i ] % 10 + 1 ) ; } Console . WriteLine ( arr [ N ] ) ; } public static void Main ( String [ ] args ) { int N = 21 ; findNthNumber ( N ) ; } }
Unique element in an array where all elements occur K times except one | Set 2 | C # program for the above approach ; Function that find the unique element in the array [ ] arr ; Store all unique element in set ; Sum of all element of the array ; Sum of element in the set ; Print the unique element using formula ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static void findUniqueElements ( int [ ] arr , int N , int K ) { HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) s . Add ( arr [ i ] ) ; int arr_sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) arr_sum += arr [ i ] ; int set_sum = 0 ; foreach ( int i in s ) set_sum += i ; Console . WriteLine ( ( K * set_sum - arr_sum ) / ( K - 1 ) ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 12 , 1 , 12 , 3 , 12 , 1 , 1 , 2 , 3 , 2 , 2 , 3 , 7 } ; int N = arr . Length ; int K = 3 ; findUniqueElements ( arr , N , K ) ; } }
Form the Cubic equation from the given roots | C # program for the approach ; Function to find the cubic equation whose roots are a , b and c ; Find the value of coefficient ; Print the equation as per the above coefficients ; Driver Code ; Function Call
using System ; class GFG { static void findEquation ( int a , int b , int c ) { int X = ( a + b + c ) ; int Y = ( a * b ) + ( b * c ) + ( c * a ) ; int Z = a * b * c ; Console . Write ( " x ^ 3 ▁ - ▁ " + X + " x ^ 2 ▁ + ▁ " + Y + " x ▁ - ▁ " + Z + " ▁ = ▁ 0" ) ; } public static void Main ( ) { int a = 5 , b = 2 , c = 3 ; findEquation ( a , b , c ) ; } }
Gill 's 4th Order Method to solve Differential Equations | C # program to implement Gill 's method ; A sample differential equation " dy / dx ▁ = ▁ ( x ▁ - ▁ y ) /2" ; Finds value of y for a given x using step size h and initial value y0 at x0 ; Count number of iterations using step size or height h ; Value of K_i ; Initial value of y ( 0 ) ; Iterate for number of iteration ; Value of K1 ; Value of K2 ; Value of K3 ; Value of K4 ; Find the next value of y ( n + 1 ) using y ( n ) and values of K in the above steps ; Update next value of x ; Return the final value of dy / dx ; Driver Code
using System ; class GFG { static double dydx ( double x , double y ) { return ( x - y ) / 2 ; } static double Gill ( double x0 , double y0 , double x , double h ) { int n = ( int ) ( ( x - x0 ) / h ) ; double k1 , k2 , k3 , k4 ; double y = y0 ; for ( int i = 1 ; i <= n ; i ++ ) { k1 = h * dydx ( x0 , y ) ; k2 = h * dydx ( x0 + 0.5 * h , y + 0.5 * k1 ) ; k3 = h * dydx ( x0 + 0.5 * h , y + 0.5 * ( - 1 + Math . Sqrt ( 2 ) ) * k1 + k2 * ( 1 - 0.5 * Math . Sqrt ( 2 ) ) ) ; k4 = h * dydx ( x0 + h , y - ( 0.5 * Math . Sqrt ( 2 ) ) * k2 + k3 * ( 1 + 0.5 * Math . Sqrt ( 2 ) ) ) ; y = y + ( 1.0 / 6 ) * ( k1 + ( 2 - Math . Sqrt ( 2 ) ) * k2 + ( 2 + Math . Sqrt ( 2 ) ) * k3 + k4 ) ; x0 = x0 + h ; } return y ; } public static void Main ( String [ ] args ) { double x0 = 0 , y = 3.0 , x = 5.0 , h = 0.2 ; Console . Write ( " y ( x ) ▁ = ▁ { 0 : F6 } " , Gill ( x0 , y , x , h ) ) ; } }
Program to print numbers from N to 1 in reverse order | C # program to print all numbers between 1 to N in reverse order ; Recursive function to print from N to 1 ; Driver code
using System ; class GFG { static void PrintReverseOrder ( int N ) { for ( int i = N ; i > 0 ; i -- ) Console . Write ( i + " ▁ " ) ; } public static void Main ( String [ ] args ) { int N = 5 ; PrintReverseOrder ( N ) ; } }
Find count of numbers from 0 to n which satisfies the given equation for a value K | C # implementation to find the total count of all the numbers from 0 to n which satisfies the given equation for a value K ; Function to find the values ; Calculate the LCM ; Calculate the multiples of lcm ; Find the values which satisfies the given condition ; Subtract the extra values ; Return the readonly result ; Driver code
using System ; class GFG { static int findAns ( int a , int b , int n ) { int lcm = ( a * b ) / __gcd ( a , b ) ; int multiples = ( n / lcm ) + 1 ; int answer = Math . Max ( a , b ) * multiples ; int lastvalue = lcm * ( n / lcm ) + Math . Max ( a , b ) ; if ( lastvalue > n ) { answer = answer - ( lastvalue - n - 1 ) ; } return answer ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int a = 1 , b = 13 , n = 500 ; Console . Write ( findAns ( a , b , n ) + " STRNEWLINE " ) ; } }
Program to find if two numbers and their AM and HM are present in an array using STL | C # program to check if two numbers are present in an array then their AM and HM are also present . Finally , find the GM of the numbers ; Function to find the Arithmetic Mean of 2 numbers ; Function to find the Harmonic Mean of 2 numbers ; Following function checks and computes the desired results based on the means ; Calculate means ; Hash container ( Set ) to store elements HashMap < Double , int > Hash = new HashMap < Double , int > ( ) ; ; Insertion of array elements in the Set ; Conditionals to check if numbers are present in array by Hashing ; Conditionals to check if the AM and HM of the numbers are present in array ; If all conditions are satisfied , the Geometric Mean is calculated ; If numbers are found but the respective AM and HM are not found in the array ; If none of the conditions are satisfied ; Driver code
using System ; using System . Collections . Generic ; class GFG { static Double ArithmeticMean ( Double A , Double B ) { return ( A + B ) / 2 ; } static Double HarmonicMean ( Double A , Double B ) { return ( 2 * A * B ) / ( A + B ) ; } static void CheckArithmeticHarmonic ( Double [ ] arr , Double A , Double B , int N ) { Double AM = ArithmeticMean ( A , B ) ; Double HM = HarmonicMean ( A , B ) ; Dictionary < Double , int > Hash = new Dictionary < Double , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Hash [ arr [ i ] ] = 1 ; } if ( Hash . ContainsKey ( A ) && Hash . ContainsKey ( B ) ) { if ( Hash . ContainsKey ( AM ) && Hash . ContainsKey ( HM ) ) { Console . Write ( " GM ▁ = ▁ " ) ; Console . Write ( Math . Round ( Math . Sqrt ( AM * HM ) , 2 ) ) ; } else { Console . WriteLine ( " AM ▁ and ▁ HM ▁ not ▁ found " ) ; } } else { Console . WriteLine ( " numbers ▁ not ▁ found " ) ; } } public static void Main ( ) { Double [ ] arr = { 1.0 , 2.0 , 2.5 , 3.0 , 4.0 , 4.5 , 5.0 , 6.0 } ; int N = ( arr . Length ) ; Double A = 3.0 ; Double B = 6.0 ; CheckArithmeticHarmonic ( arr , A , B , N ) ; } }
Minimum decrements to make integer A divisible by integer B | C # implementation to count total numbers moves to make integer A divisible by integer B ; Function that print number of moves required ; Calculate modulo ; Print the required answer ; Driver code ; Initialise A and B
using System ; class GFG { static void movesRequired ( int a , int b ) { int total_moves = a % b ; Console . Write ( total_moves ) ; } public static void Main ( String [ ] args ) { int A = 10 , B = 3 ; movesRequired ( A , B ) ; } }
Pythagorean Triplet with given sum using single loop | C # program to find the Pythagorean Triplet with given sum ; Function to calculate the Pythagorean triplet in O ( n ) ; Iterate a from 1 to N - 1. ; Calculate value of b ; The value of c = n - a - b ; Driver code ; Function call
using System ; class GFG { static void PythagoreanTriplet ( int n ) { int flag = 0 ; for ( int a = 1 ; a < n ; a ++ ) { int b = ( n * n - 2 * n * a ) / ( 2 * n - 2 * a ) ; int c = n - a - b ; if ( a * a + b * b == c * c && b > 0 && c > 0 ) { Console . Write ( a + " ▁ " + b + " ▁ " + c ) ; flag = 1 ; break ; } } if ( flag == 0 ) { Console . Write ( " - 1" ) ; } return ; } public static void Main ( String [ ] args ) { int N = 12 ; PythagoreanTriplet ( N ) ; } }
Check if there exists a number with X factors out of which exactly K are prime | C # program to check if there exists a number with X factors out of which exactly K are prime ; Function to check if such number exists ; To store the sum of powers of prime factors of X which determines the maximum count of numbers whose product can form X ; Determining the prime factors of X ; To check if the number is prime ; If X is 1 , then we cannot form a number with 1 factor and K prime factor ( as K is atleast 1 ) ; If X itself is prime then it can be represented as a power of only 1 prime factor which is X itself so we return true ; If sum of the powers of prime factors of X is greater than or equal to K , which means X can be represented as a product of K numbers , we return true ; In any other case , we return false as we cannot form a number with X factors and K prime factors ; Driver code
using System ; class GFG { static bool check ( int X , int K ) { int prime , temp , sqr , i ; prime = 0 ; temp = X ; sqr = Convert . ToInt32 ( Math . Sqrt ( X ) ) ; for ( i = 2 ; i <= sqr ; i ++ ) { while ( temp % i == 0 ) { temp = temp / i ; prime ++ ; } } if ( temp > 2 ) prime ++ ; if ( X == 1 ) return false ; if ( prime == 1 && K == 1 ) return true ; else if ( prime >= K ) return true ; else return false ; } static public void Main ( ) { int X , K ; X = 4 ; K = 2 ; if ( check ( X , K ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Number of subsets with same AND , OR and XOR values in an Array | C # implementation to find the number of subsets with equal bitwise AND , OR and XOR values ; Function to find the number of subsets with equal bitwise AND , OR and XOR values ; Traverse through all the subsets ; Finding the subsets with the bits of ' i ' which are set ; Computing the bitwise AND ; Computing the bitwise OR ; Computing the bitwise XOR ; Comparing all the three values ; Driver Code
using System ; class GFG { static int mod = 1000000007 ; static int countSubsets ( int [ ] a , int n ) { int answer = 0 ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { int bitwiseAND = - 1 ; int bitwiseOR = 0 ; int bitwiseXOR = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) == 0 ) { if ( bitwiseAND == - 1 ) bitwiseAND = a [ j ] ; else bitwiseAND &= a [ j ] ; bitwiseOR |= a [ j ] ; bitwiseXOR ^= a [ j ] ; } } if ( bitwiseAND == bitwiseOR && bitwiseOR == bitwiseXOR ) answer = ( answer + 1 ) % mod ; } return answer ; } public static void Main ( String [ ] args ) { int N = 6 ; int [ ] A = { 1 , 3 , 2 , 1 , 2 , 1 } ; Console . Write ( countSubsets ( A , N ) ) ; } }
Count of Subsets containing only the given value K | C # implementation to find the number of subsets formed by the given value K ; Function to find the number of subsets formed by the given value K ; Count is used to maintain the number of continuous K 's ; Iterating through the array ; If the element in the array is equal to K ; count * ( count + 1 ) / 2 is the total number of subsets with only K as their element ; Change count to 0 because other element apart from K has been found ; To handle the last set of K 's ; Driver code
using System ; class GFG { static int count ( int [ ] arr , int N , int K ) { int count = 0 , ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == K ) { count = count + 1 ; } else { ans += ( count * ( count + 1 ) ) / 2 ; count = 0 ; } } ans = ans + ( count * ( count + 1 ) ) / 2 ; return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 0 , 0 , 1 , 1 , 0 , 0 } ; int N = arr . Length ; int K = 0 ; Console . Write ( count ( arr , N , K ) ) ; } }
Ternary number system or Base 3 numbers | C # program to convert decimal number to ternary number ; Function to convert a decimal number to a ternary number ; Base case ; Finding the remainder when N is divided by 3 ; Recursive function to call the function for the integer division of the value N / 3 ; Handling the negative cases ; Function to convert the decimal to ternary ; If the number is greater than 0 , compute the ternary representation of the number ; Driver Code
using System ; class GFG { static void convertToTernary ( int N ) { if ( N == 0 ) return ; int x = N % 3 ; N /= 3 ; if ( x < 0 ) N += 1 ; convertToTernary ( N ) ; if ( x < 0 ) Console . Write ( x + ( 3 * - 1 ) ) ; else Console . Write ( x ) ; } static void convert ( int Decimal ) { Console . Write ( " Ternary ▁ number ▁ of ▁ " + Decimal + " ▁ is : ▁ " ) ; if ( Decimal != 0 ) { convertToTernary ( Decimal ) ; } else Console . WriteLine ( "0" ) ; } public static void Main ( string [ ] args ) { int Decimal = 2747 ; convert ( Decimal ) ; } }
Largest number less than or equal to Z that leaves a remainder X when divided by Y | C # implementation to Find the largest non - negative number that is less than or equal to integer Z and leaves a remainder X when divided by Y ; Function to get the number ; remainder can ' t ▁ be ▁ larger ▁ ▁ than ▁ the ▁ largest ▁ number , ▁ ▁ if ▁ so ▁ then ▁ answer ▁ doesn ' t exist . ; reduce number by x ; finding the possible number that is divisible by y ; this number is always <= x as we calculated over z - x ; Driver Code ; initialise the three integers
using System ; class GFG { static int get ( int x , int y , int z ) { if ( x > z ) return - 1 ; int val = z - x ; int div = ( z - x ) / y ; int ans = div * y + x ; return ans ; } public static void Main ( String [ ] args ) { int x = 1 , y = 5 , z = 8 ; Console . Write ( get ( x , y , z ) + " STRNEWLINE " ) ; } }
Find the conjugate of a Complex number | C # implementation to find the conjugate of a complex number ; Function to find conjugate of a complex number ; Store index of ' + ' ; Store index of ' - ' ; print the result ; Driver code ; Initialise the complex number
using System ; class GFG { static void solve ( String s ) { String z = s ; int l = s . Length ; int i ; String str ; if ( s . IndexOf ( ' + ' ) != - 1 ) { i = s . IndexOf ( ' + ' ) ; str = s . Replace ( ' + ' , ' - ' ) ; } else { i = s . IndexOf ( ' - ' ) ; str = s . Replace ( ' - ' , ' + ' ) ; } Console . WriteLine ( " Conjugate ▁ of ▁ " + z + " ▁ = ▁ " + str ) ; } public static void Main ( String [ ] args ) { String s = "3-4i " ; solve ( s ) ; } }
Minimum operations required to make two numbers equal | C # program to find minimum operations required to make two numbers equal ; Function to return the minimum operations required ; Keeping B always greater ; Reduce B such that gcd ( A , B ) becomes 1. ; Driver code
using System ; class GFG { static int minOperations ( int A , int B ) { if ( A > B ) { A = A + B ; B = A - B ; A = A - B ; } B = B / __gcd ( A , B ) ; return B - 1 ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int A = 7 , B = 15 ; Console . Write ( minOperations ( A , B ) + " STRNEWLINE " ) ; } }
Program to determine the Quadrant of a Complex number | C # program to determine the quadrant of a complex number ; Function to determine the quadrant of a complex number ; Storing the index of ' + ' ; Storing the index of ' - ' ; Finding the real part of the complex number ; Finding the imaginary part of the complex number ; Driver code
using System ; class GFG { static void quadrant ( String s ) { int l = s . Length ; int i ; if ( s . Contains ( " + " ) ) { i = s . IndexOf ( ' + ' ) ; } else { i = s . IndexOf ( ' - ' ) ; } String real = s . Substring ( 0 , i ) ; String imaginary = s . Substring ( i + 1 , l - 2 - i ) ; int x = Int32 . Parse ( real ) ; int y = Int32 . Parse ( imaginary ) ; if ( x > 0 && y > 0 ) Console . Write ( " Quadrant ▁ 1" ) ; else if ( x < 0 && y > 0 ) Console . Write ( " Quadrant ▁ 2" ) ; else if ( x < 0 && y < 0 ) Console . Write ( " Quadrant ▁ 3" ) ; else if ( x > 0 && y < 0 ) Console . Write ( " Quadrant ▁ 4" ) ; else if ( x == 0 && y > 0 ) Console . Write ( " Lies ▁ on ▁ positive " + " ▁ Imaginary ▁ axis " ) ; else if ( x == 0 && y < 0 ) Console . Write ( " Lies ▁ on ▁ negative " + " ▁ Imaginary ▁ axis " ) ; else if ( y == 0 && x < 0 ) Console . Write ( " Lies ▁ on ▁ negative " + " ▁ X - axis " ) ; else if ( y == 0 && x > 0 ) Console . Write ( " Lies ▁ on ▁ positive " + " ▁ X - axis " ) ; else Console . Write ( " Lies ▁ on ▁ the ▁ Origin " ) ; } public static void Main ( String [ ] args ) { String s = "5 + 3i " ; quadrant ( s ) ; } }
Sum and Product of all Fibonacci Nodes of a Singly Linked List | C # implementation to find the sum and product of all of the Fibonacci nodes in a singly linked list ; Node of the singly linked list ; Function to insert a node at the beginning of the singly Linked List ; Allocate new node ; Insert the data ; Link the old list to the new node ; Move the head to point the new node ; Function that returns the largest element from the linked list . ; Declare a max variable and initialize with int . MinValue ; Check loop while head not equal to null ; If max is less then head . data then assign value of head . data to max otherwise node points to next node . ; Function to create a hash table to check Fibonacci numbers ; Inserting the first two numbers in the hash ; Loop to add Fibonacci numbers upto the maximum element present in the linked list ; Function to find the required sum and product ; Find the largest node value in Singly Linked List ; Creating a set containing all the fibonacci numbers upto the maximum data value in the Singly Linked List ; Traverse the linked list ; If current node is fibonacci ; Find the sum and the product ; Driver code ; Create the linked list 15.16 . 8.6 .13
using System ; using System . Collections . Generic ; class GFG { class Node { public int data ; public Node next ; } ; static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = head_ref ; head_ref = new_node ; return head_ref ; } static int largestElement ( Node head_ref ) { int max = int . MinValue ; Node head = head_ref ; while ( head != null ) { if ( max < head . data ) max = head . data ; head = head . next ; } return max ; } static void createHash ( HashSet < int > hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . Add ( prev ) ; hash . Add ( curr ) ; while ( curr <= maxElement ) { int temp = curr + prev ; hash . Add ( temp ) ; prev = curr ; curr = temp ; } } static void sumAndProduct ( Node head_ref ) { int maxEle = largestElement ( head_ref ) ; HashSet < int > hash = new HashSet < int > ( ) ; createHash ( hash , maxEle ) ; int prod = 1 ; int sum = 0 ; Node ptr = head_ref ; while ( ptr != null ) { if ( hash . Contains ( ptr . data ) ) { prod *= ptr . data ; sum += ptr . data ; } ptr = ptr . next ; } Console . Write ( " Sum ▁ = ▁ " + sum + " STRNEWLINE " ) ; Console . Write ( " Product ▁ = ▁ " + prod ) ; } public static void Main ( String [ ] args ) { Node head = null ; head = push ( head , 13 ) ; head = push ( head , 6 ) ; head = push ( head , 8 ) ; head = push ( head , 16 ) ; head = push ( head , 15 ) ; sumAndProduct ( head ) ; } }
Product of all Subarrays of an Array | C # program to find product of all subarray of an array ; Function to find product of all subarrays ; Variable to store the product ; Compute the product while traversing for subarrays ; Printing product of all subarray ; Driver code ; Function call
using System ; class GFG { static void product_subarrays ( int [ ] arr , int n ) { int product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { for ( int k = i ; k <= j ; k ++ ) product *= arr [ k ] ; } } Console . Write ( product + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 10 , 3 , 7 } ; int n = arr . Length ; product_subarrays ( arr , n ) ; } }