codeparrot/xlcost-text-to-code huggingface dataset:
Sum of all subsequences of a number | C # program to find the sum of elements present in all subsequences ; Returns numeric value of a subsequence of s . The subsequence to be picked is decided using bit pattern of num ( We pick all those digits for which there is a set bit in num ) ; Initialize the result ; till n != 0 ; if i - th bit is set then add this number ; right shift i ; function to find combined sum of all individual subsequence sum ; length of string ; stores the combined ; 2 ^ n - 1 subsequences ; loop for all subsequences ; returns the combined sum ; Driver function
using System ; class GFG { static int findSubSequence ( string s , int num ) { int res = 0 ; int i = 0 ; while ( num > 0 ) { if ( ( num & 1 ) == 1 ) res += s [ i ] - '0' ; i ++ ; num = num >> 1 ; } return res ; } static int combinedSum ( string s ) { int n = s . Length ; int c_sum = 0 ; int range = ( 1 << n ) - 1 ; for ( int i = 0 ; i <= range ; i ++ ) c_sum += findSubSequence ( s , i ) ; return c_sum ; } public static void Main ( ) { string s = "123" ; Console . Write ( combinedSum ( s ) ) ; } }
Longest subsequence where each character occurs at least k times | C # Program to find the subsequence with each character occurring at least k times in string s ; Function to find the subsequence ; Taking an extra array to keep record for character count in s ; Counting occurrences of all characters in str [ ] ; Printing characters with count >= k in same order as they appear in str . ; Driver code
using System ; class GFG { static int MAX_CHAR = 26 ; static void findSubsequence ( string str , int k ) { int [ ] a = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < str . Length ; i ++ ) a [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < str . Length ; i ++ ) if ( a [ str [ i ] - ' a ' ] >= k ) Console . Write ( str [ i ] ) ; } public static void Main ( ) { int k = 2 ; findSubsequence ( " geeksforgeeks " , k ) ; } }
gOOGLE cASE of a given sentence | C # program to convert a sentence to gOOGLE cASE . ; empty strings ; convert input string to upper case ; checki if character is not a space and adding it to string w ; converting first character to lower case and subsequent initial letter of another word to lower case ; Driver code
using System ; class GFG { static string convert ( string str ) { string w = " " , z = " " ; str = str . ToUpper ( ) + " ▁ " ; for ( int i = 0 ; i < str . Length ; i ++ ) { char ch = str [ i ] ; if ( ch != ' ▁ ' ) w = w + ch ; else { z = z + ( Char . ToLower ( w [ 0 ] ) ) + w . Substring ( 1 ) + " ▁ " ; w = " " ; } } return z ; } static void Main ( ) { string str = " I ▁ got ▁ intern ▁ at ▁ geeksforgeeks " ; Console . WriteLine ( convert ( str ) ) ; } }
Encrypt string with product of number of vowels and consonants in substring of size k | C # Program to Encrypt String with product of number of vowels and consonants in subString of size k ; isVowel ( ) is a function that returns true for a vowel and false otherwise . ; function to Encrypt the String ; cv to count vowel cc to count consonants ; Counting prefix count of vowel and prefix count of consonants ; generating the encrypted String . ; Driver Code
using System ; class GFG { static bool isVowel ( char c ) { return ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static String encryptString ( char [ ] s , int n , int k ) { int [ ] cv = new int [ n ] ; int [ ] cc = new int [ n ] ; if ( isVowel ( s [ 0 ] ) ) cv [ 0 ] = 1 ; else cc [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { cv [ i ] = cv [ i - 1 ] + ( isVowel ( s [ i ] ) == true ? 1 : 0 ) ; cc [ i ] = cc [ i - 1 ] + ( isVowel ( s [ i ] ) == true ? 0 : 1 ) ; } String ans = " " ; int prod = 0 ; prod = cc [ k - 1 ] * cv [ k - 1 ] ; ans += String . Join ( " " , prod ) ; for ( int i = k ; i < s . Length ; i ++ ) { prod = ( cc [ i ] - cc [ i - k ] ) * ( cv [ i ] - cv [ i - k ] ) ; ans += String . Join ( " " , prod ) ; } return ans ; } public static void Main ( String [ ] args ) { String s = " hello " ; int n = s . Length ; int k = 2 ; Console . Write ( encryptString ( s . ToCharArray ( ) , n , k ) + " STRNEWLINE " ) ; } }
Count occurrences of a word in string | C # program to count the number of occurrence of a word in the given string ; split the string by spaces ; search for pattern in string ; if match found increase count ; Driver code
using System ; class GFG { static int countOccurrences ( string str , string word ) { string [ ] a = str . Split ( ' ▁ ' ) ; int count = 0 ; for ( int i = 0 ; i < a . Length ; i ++ ) { if ( word . Equals ( a [ i ] ) ) count ++ ; } return count ; } public static void Main ( ) { string str = " GeeksforGeeks ▁ A ▁ computer ▁ science ▁ portal ▁ for ▁ geeks ▁ " ; string word = " portal " ; Console . Write ( countOccurrences ( str , word ) ) ; } }
Permute a string by changing case | C # program to print all permutations with respect to cases ; Function to generate permutations ; Number of permutations is 2 ^ n ; Converting string to lower case ; Using all subsequences and permuting them ; If j - th bit is set , we convert it to upper case ; Printing current combination ; Driver Code
using System ; class PermuteString { static void permute ( String input ) { int n = input . Length ; int max = 1 << n ; input = input . ToLower ( ) ; for ( int i = 0 ; i < max ; i ++ ) { char [ ] combination = input . ToCharArray ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( ( i >> j ) & 1 ) == 1 ) combination [ j ] = ( char ) ( combination [ j ] - 32 ) ; } Console . Write ( combination ) ; Console . Write ( " ▁ " ) ; } } public static void Main ( ) { permute ( " ABC " ) ; } }
Print the string after the specified character has occurred given no . of times | C # program for above implementation ; Method to print the string ; If given count is 0 print the given string and return ; Start traversing the string ; Increment occ if current char is equal to given character ; Break the loop if given character has been occurred given no . of times ; Print the string after the occurrence of given character given no . of times ; Otherwise string is empty ; Driver Method
using System ; public class GFG { static public void printString ( string str , char ch , int count ) { int occ = 0 , i ; if ( count == 0 ) { Console . WriteLine ( str ) ; return ; } for ( i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == ch ) occ ++ ; if ( occ == count ) break ; } if ( i < str . Length - 1 ) Console . WriteLine ( str . Substring ( i + 1 ) ) ; else Console . WriteLine ( " Empty ▁ string " ) ; } static public void Main ( ) { string str = " geeks ▁ for ▁ geeks " ; printString ( str , ' e ' , 2 ) ; } }
Reverse vowels in a given string | C # program to reverse order of vowels ; utility function to check for vowel ; Function to reverse order of vowels ; Start two indexes from two corners and move toward each other ; swapping ; Driver code
using System ; class GFG { static Boolean isVowel ( char c ) { return ( c == ' a ' c == ' A ' c == ' e ' c == ' E ' c == ' i ' c == ' I ' c == ' o ' c == ' O ' c == ' u ' c == ' U ' ) ; } static String reverseVowel ( String str ) { int i = 0 ; int j = str . Length - 1 ; char [ ] str1 = str . ToCharArray ( ) ; while ( i < j ) { if ( ! isVowel ( str1 [ i ] ) ) { i ++ ; continue ; } if ( ! isVowel ( str1 [ j ] ) ) { j -- ; continue ; } char t = str1 [ i ] ; str1 [ i ] = str1 [ j ] ; str1 [ j ] = t ; i ++ ; j -- ; } String str2 = String . Join ( " " , str1 ) ; return str2 ; } public static void Main ( String [ ] args ) { String str = " hello ▁ world " ; Console . WriteLine ( reverseVowel ( str ) ) ; } }
Minimum number of palindromic subsequences to be removed to empty a binary string | C # program to count minimum palindromic subsequences to be removed to make an string empty . ; A function to check if a string str is palindrome ; Start from leftmost and rightmost corners of str ; Keep comparing characters while they are same ; Returns count of minimum palindromic subseuqnces to be removed to make string empty ; If string is empty ; If string is palindrome ; If string is not palindrome ; Driver code to
using System ; class GFG { static bool isPalindrome ( String str ) { int l = 0 ; int h = str . Length - 1 ; while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ; return true ; } static int minRemovals ( String str ) { if ( str [ 0 ] == ' ' ) return 0 ; if ( isPalindrome ( str ) ) return 1 ; return 2 ; } public static void Main ( ) { Console . WriteLine ( minRemovals ( "010010" ) ) ; Console . WriteLine ( minRemovals ( "0100101" ) ) ; } }
Find the value of XXXX ... . . ( N times ) % M where N is large | C # implementation of the approach ; Iterative function to calculate ( x ^ y ) % p in O ( log y ) ; Initialize result ; Update x if it is >= p ; If y is odd , multiply x with result ; y must be even now y = y / 2 ; Function to return XXX ... . . ( N times ) % M ; Return the mod by M of smaller numbers ; Creating a string of N X 's ; Converting the string to int and calculating the modulo ; Checking the parity of N ; Dividing the number into equal half ; Utilizing the formula for even N ; Dividing the number into equal half ; Utilizing the formula for odd N ; Driver code ; Print XXX ... ( N times ) % M
using System ; class GFG { static int power ( int x , int y , int p ) { 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 findModuloByM ( int X , int N , int M ) { if ( N < 6 ) { string temp = " " ; for ( int i = 0 ; i < N ; i ++ ) temp = temp + ( char ) ( X + 48 ) ; int res = Convert . ToInt32 ( temp ) % M ; return res ; } if ( N % 2 == 0 ) { int half = findModuloByM ( X , N / 2 , M ) % M ; int res = ( half * power ( 10 , N / 2 , M ) + half ) % M ; return res ; } else { int half = findModuloByM ( X , N / 2 , M ) % M ; int res = ( half * power ( 10 , N / 2 + 1 , M ) + half * 10 + X ) % M ; return res ; } } public static void Main ( ) { int X = 6 , N = 14 , M = 9 ; Console . WriteLine ( findModuloByM ( X , N , M ) ) ; } }
Check if two circles intersect such that the third circle passes through their points of intersections and centers | C # approach for the above approach ; Structure of the circle ; Utility function to check if given circles satisfy required criteria ; Stores the distance between the centres of C1 and C2 ; Stores the status if the given given criteria is satisfied or not ; If C1C2 is less than the sum of the radii of the first 2 circles ; If C3 is the midpoint of the centres at C1 and C2 ; Mark flag true ; Return flag ; Function to check if the given circles satisfy required criteria ; Check for the current combination of circles ; Check for the next combination ; Driver Code
using System ; class GFG { class circle { public double x ; public double y ; public double r ; public circle ( int x , int y , int r ) { this . x = x ; this . y = y ; this . r = r ; } } static bool check ( circle [ ] C ) { double C1C2 = Math . Sqrt ( ( C [ 1 ] . x - C [ 0 ] . x ) * ( C [ 1 ] . x - C [ 0 ] . x ) + ( C [ 1 ] . y - C [ 0 ] . y ) * ( C [ 1 ] . y - C [ 0 ] . y ) ) ; bool flag = false ; if ( C1C2 < ( C [ 0 ] . r + C [ 1 ] . r ) ) { if ( ( C [ 0 ] . x + C [ 1 ] . x ) == 2 * C [ 2 ] . x && ( C [ 0 ] . y + C [ 1 ] . y ) == 2 * C [ 2 ] . y ) { flag = true ; } } return flag ; } static bool IsFairTriplet ( circle [ ] c ) { bool f = false ; f |= check ( c ) ; for ( int i = 0 ; i < 2 ; i ++ ) { swap ( c [ 0 ] , c [ 2 ] ) ; f |= check ( c ) ; } return f ; } static void swap ( circle circle1 , circle circle2 ) { circle temp = circle1 ; circle1 = circle2 ; circle2 = temp ; } public static void Main ( String [ ] args ) { circle [ ] C = new circle [ 3 ] ; C [ 0 ] = new circle ( 0 , 0 , 8 ) ; C [ 1 ] = new circle ( 0 , 10 , 6 ) ; C [ 2 ] = new circle ( 0 , 5 , 5 ) ; if ( IsFairTriplet ( C ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Program to find the Eccentricity of a Hyperbola | C # program for the above approach ; Function to find the eccentricity of a hyperbola ; Stores the squared ratio of major axis to minor axis ; Increment r by 1 ; Return the square root of r ; Driver Code
using System ; class GFG { static double eccHyperbola ( double A , double B ) { double r = ( double ) B * B / A * A ; r += 1 ; return Math . Sqrt ( r ) ; } public static void Main ( String [ ] args ) { double A = 3.0 , B = 2.0 ; Console . Write ( eccHyperbola ( A , B ) ) ; } }
Calculate area of a cyclic quadrilateral with given side lengths | C # program for the above approach ; Function to find the area of cyclic quadrilateral ; Stores the value of half of the perimeter ; Stores area of cyclic quadrilateral ; Return the resultant area ; Driver Code
using System ; class GFG { static float calculateArea ( float A , float B , float C , float D ) { float S = ( A + B + C + D ) / 2 ; float area = ( float ) Math . Sqrt ( ( S - A ) * ( S - B ) * ( S - C ) * ( S - D ) ) ; return area ; } static public void Main ( ) { float A = 10 ; float B = 15 ; float C = 20 ; float D = 25 ; Console . Write ( calculateArea ( A , B , C , D ) ) ; } }
Calculate ratio of area of a triangle inscribed in an Ellipse and the triangle formed by corresponding points on auxiliary circle | C # program for the above approach ; Function to calculate ratio of a triangle inscribed in an ellipse to the triangle on the auxiliary circle ; Stores the ratio of the semi - major to semi - minor axes ; Print the ratio ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void triangleArea ( int a , int b ) { double ratio = ( double ) b / a ; Console . WriteLine ( ratio ) ; } public static void Main ( ) { int a = 1 , b = 2 ; triangleArea ( a , b ) ; } }
Program to find the Excenters of a Triangle | C # program for the above approach ; Function to calculate the distance between a pair of points ; Function to calculate the coordinates of the excenters of a triangle ; Length of the sides of the triangle ; Stores the coordinates of the excenters of the triangle ; For I1 ; For I2 ; For I3 ; Print the excenters of the triangle ; Driver code
using System ; class GFG { class pair { public float first , second ; public pair ( float first , float second ) { this . first = first ; this . second = second ; } } static float distance ( int m , int n , int p , int q ) { return ( float ) Math . Sqrt ( Math . Pow ( n - m , 2 ) + Math . Pow ( q - p , 2 ) * 1.0 ) ; } static void Excenters ( int x1 , int y1 , int x2 , int y2 , int x3 , int y3 ) { float a = distance ( x2 , x3 , y2 , y3 ) ; float b = distance ( x3 , x1 , y3 , y1 ) ; float c = distance ( x1 , x2 , y1 , y2 ) ; pair [ ] excenter = new pair [ 4 ] ; excenter [ 1 ] = new pair ( ( - ( a * x1 ) + ( b * x2 ) + ( c * x3 ) ) / ( - a + b + c ) , ( - ( a * y1 ) + ( b * y2 ) + ( c * y3 ) ) / ( - a + b + c ) ) ; excenter [ 2 ] = new pair ( ( ( a * x1 ) - ( b * x2 ) + ( c * x3 ) ) / ( a - b + c ) , ( ( a * y1 ) - ( b * y2 ) + ( c * y3 ) ) / ( a - b + c ) ) ; excenter [ 3 ] = new pair ( ( ( a * x1 ) + ( b * x2 ) - ( c * x3 ) ) / ( a + b - c ) , ( ( a * y1 ) + ( b * y2 ) - ( c * y3 ) ) / ( a + b - c ) ) ; for ( int i = 1 ; i <= 3 ; i ++ ) { Console . WriteLine ( ( int ) excenter [ i ] . first + " ▁ " + ( int ) excenter [ i ] . second ) ; } } static void Main ( ) { int x1 , x2 , x3 , y1 , y2 , y3 ; x1 = 0 ; x2 = 3 ; x3 = 0 ; y1 = 0 ; y2 = 0 ; y3 = 4 ; Excenters ( x1 , y1 , x2 , y2 , x3 , y3 ) ; } }
Program to find height of a Trapezoid | C # program to implement the above approach ; Function to calculate height of the trapezoid ; Apply Heron 's formula ; Calculate the area ; Calculate height of trapezoid ; Print the height ; Driver Code ; Given a , b , p1 and p2
using System ; public class GFG { static void findHeight ( float p1 , float p2 , float b , float c ) { float a = Math . Max ( p1 , p2 ) - Math . Min ( p1 , p2 ) ; float s = ( a + b + c ) / 2 ; float area = ( int ) Math . Sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ; float height = ( area * 2 ) / a ; Console . Write ( " Height ▁ is : ▁ " + height ) ; } public static void Main ( String [ ] args ) { float p1 = 25 , p2 = 10 ; float a = 14 , b = 13 ; findHeight ( p1 , p2 , a , b ) ; } }
Icositetragonal Number | C # program to find nth icositetragonal number ; Function to find icositetragonal number ; Formula to calculate nth icositetragonal number ; Driver code
using System ; class GFG { static int Icositetragonal_num ( int n ) { return ( 22 * n * n - 20 * n ) / 2 ; } public static void Main ( string [ ] args ) { int n = 3 ; Console . Write ( Icositetragonal_num ( n ) + " STRNEWLINE " ) ; n = 10 ; Console . Write ( Icositetragonal_num ( n ) + " STRNEWLINE " ) ; } }
Area of circle inscribed in a Isosceles Trapezoid | C # Program to find the rea of the circle inscribed in a trapezoid having non - parallel sides m , n ; Function to find area of circle inscribed in a trapezoid having non - parallel sides m , n ; radius of circle by the formula i . e . root ( m * n ) / 2 area of circle = ( 3.141 ) * ( R * * 2 ) ; Driver code
using System ; class GFG { static double area_of_circle ( int m , int n ) { int square_of_radius = ( m * n ) / 4 ; double area = ( 3.141 * square_of_radius ) ; return area ; } public static void Main ( ) { int n = 10 ; int m = 30 ; Console . WriteLine ( area_of_circle ( m , n ) ) ; } }
Area of Equilateral triangle inscribed in a Circle of radius R | C # implementation to find the area of the equilateral triangle inscribed in a circle of radius R ; Function to find the area of equilateral triangle inscribed in a circle of radius R ; Base and Height of equilateral triangle ; Area using Base and Height ; Driver code
using System ; class GFG { static double area ( int R ) { double Base = 1.732 * R ; double height = ( 1.5 ) * R ; double area = 0.5 * Base * height ; return area ; } public static void Main ( String [ ] args ) { int R = 7 ; Console . WriteLine ( area ( R ) ) ; } }
Area of largest Circle that can be inscribed in a SemiCircle | C # Program to find the biggest circle which can be inscribed within the semicircle ; Function to find the area of the circle ; Radius cannot be negative ; Area of the largest circle ; Driver code
using System ; class GFG { static float circlearea ( float R ) { if ( R < 0 ) return - 1 ; float a = ( float ) ( ( 3.14 * R * R ) / 4 ) ; return a ; } public static void Main ( string [ ] args ) { float R = 2 ; Console . WriteLine ( circlearea ( R ) ) ; } }
Number of pairs of lines having integer intersection points | C # program to Number of pairs of lines having integer intersection points ; Count number of pairs of lines having integer intersection point ; Initialize arrays to store counts ; Count number of odd and even Pi ; Count number of odd and even Qi ; Return the count of pairs ; Driver code
using System ; class GFG { static int countPairs ( int [ ] P , int [ ] Q , int N , int M ) { int [ ] A = new int [ 2 ] ; int [ ] B = new int [ 2 ] ; for ( int i = 0 ; i < N ; i ++ ) A [ P [ i ] % 2 ] ++ ; for ( int i = 0 ; i < M ; i ++ ) B [ Q [ i ] % 2 ] ++ ; return ( A [ 0 ] * B [ 0 ] + A [ 1 ] * B [ 1 ] ) ; } public static void Main ( ) { int [ ] P = { 1 , 3 , 2 } ; int [ ] Q = { 3 , 0 } ; int N = P . Length ; int M = Q . Length ; Console . Write ( countPairs ( P , Q , N , M ) ) ; } }
Maximum number of line intersections formed through intersection of N planes | C # implementation of the approach ; Function to count maximum number of intersections possible ; Driver Code
using System ; class GFG { static int countIntersections ( int n ) { return n * ( n - 1 ) / 2 ; } public static void Main ( String [ ] args ) { int n = 3 ; Console . WriteLine ( countIntersections ( n ) ) ; } }
Area of a Regular Pentagram | C # implementation of the above approach ; Function to return the area of triangle BCD ; Using Golden ratio ; Calculate area of triangle BCD ; Return area of all 5 triangle are same ; Function to return the area of regular pentagon ; Calculate the area of regular pentagon using above formula ; Return area of regular pentagon ; Function to return the area of pentagram ; Area of a pentagram is equal to the area of regular pentagon and five times the area of Triangle ; Driver code
using System ; class GFG { static double PI = 3.14159 ; static double areaOfTriangle ( float d ) { float c = ( float ) ( 1.618 * d ) ; float s = ( d + c + c ) / 2 ; double area = Math . Sqrt ( s * ( s - c ) * ( s - c ) * ( s - d ) ) ; return 5 * area ; } static double areaOfRegPentagon ( float d ) { double cal = 4 * Math . Tan ( PI / 5 ) ; double area = ( 5 * d * d ) / cal ; return area ; } static double areaOfPentagram ( float d ) { return areaOfRegPentagon ( d ) + areaOfTriangle ( d ) ; } public static void Main ( ) { float d = 5 ; Console . WriteLine ( areaOfPentagram ( d ) ) ; } }
Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given | C # program to find the angle subtended by the chord to the centre of the circle when the angle subtended by another equal chord of a congruent circle is given ; Driver code
using System ; class GFG { static void anglequichord ( int z ) { Console . WriteLine ( " The ▁ angle ▁ is ▁ " + z + " ▁ degrees " ) ; } public static void Main ( ) { int z = 48 ; anglequichord ( z ) ; } }
Program to print ASCII Value of all digits of a given number | C # program to convert the digits of a number to its ASCII values ; Function to convert digits of N to respective ASCII values ; Driver Code
using System ; public class GFG { static void convertToASCII ( int N ) { String num = N . ToString ( ) ; foreach ( char ch in num . ToCharArray ( ) ) { Console . Write ( ch + " ▁ ( " + ( int ) ch + " ) STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int N = 36 ; convertToASCII ( N ) ; } }
A Product Array Puzzle | Set 3 | C # program for the above approach ; Function to form product array with O ( n ) time and O ( 1 ) space ; Stores the product of array ; Stores the count of zeros ; Traverse the array ; If arr [ i ] is not zero ; If arr [ i ] is zero then increment count of z by 1 ; Stores the absolute value of the product ; If Z is equal to 1 ; If arr [ i ] is not zero ; Else ; If count of 0 s at least 2 ; Assign arr [ i ] = 0 ; Store absolute value of arr [ i ] ; Find the value of a / b ; If arr [ i ] and product both are less than zero ; If arr [ i ] and product both are greater than zero ; Else ; Traverse the array arr [ ] ; Driver Code ; Function Call
using System ; class GFG { static void productExceptSelf ( int [ ] arr , int N ) { int product = 1 ; int z = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != 0 ) product *= arr [ i ] ; if ( arr [ i ] == 0 ) z += 1 ; } int a = Math . Abs ( product ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( z == 1 ) { if ( arr [ i ] != 0 ) arr [ i ] = 0 ; else arr [ i ] = product ; continue ; } else if ( z > 1 ) { arr [ i ] = 0 ; continue ; } int b = Math . Abs ( arr [ i ] ) ; int curr = ( int ) Math . Round ( Math . Exp ( Math . Log ( a ) - Math . Log ( b ) ) ) ; if ( arr [ i ] < 0 && product < 0 ) arr [ i ] = curr ; else if ( arr [ i ] > 0 && product > 0 ) arr [ i ] = curr ; else arr [ i ] = - 1 * curr ; } for ( int i = 0 ; i < N ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 10 , 3 , 5 , 6 , 2 } ; int N = arr . Length ; productExceptSelf ( arr , N ) ; } }
Count subarrays made up of single | C # program for the above approach ; Function to count of subarrays made up of single digit integers only ; Stores count of subarrays ; Stores the count of consecutive single digit numbers in the array ; Traverse the array ; Increment size of block by 1 ; Increment res by count ; Assign count = 0 ; Driver Code ; Given array ; Size of the array
using System ; class GFG { static void singleDigitSubarrayCount ( int [ ] arr , int N ) { int res = 0 ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] <= 9 ) { count ++ ; res += count ; } else { count = 0 ; } } Console . Write ( res ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 0 , 1 , 14 , 2 , 5 } ; int N = arr . Length ; singleDigitSubarrayCount ( arr , N ) ; } }