codeparrot/xlcost-text-to-code huggingface dataset:
Program to calculate gross salary of a person | C # program to implement the above approach ; Function to calculate the salary of the person ; Condition to compute the allowance for the person ; Calculate gross salary ; Driver Code ; Function call
using System ; class GFG { static int computeSalary ( int basic , char grade ) { double allowance ; double hra , da , pf ; hra = 0.2 * basic ; da = 0.5 * basic ; pf = 0.11 * basic ; if ( grade == ' A ' ) { allowance = 1700.0 ; } else if ( grade == ' B ' ) { allowance = 1500.0 ; } else { allowance = 1300.0 ; } double gross ; gross = Math . Round ( basic + hra + da + allowance - pf ) ; return ( int ) gross ; } public static void Main ( String [ ] args ) { int basic = 10000 ; char grade = ' A ' ; Console . WriteLine ( computeSalary ( basic , grade ) ) ; } }
Size of smallest subarray to be removed to make count of array elements greater and smaller than K equal | C # program to implement the above approach ; Function ot find the length of the smallest subarray ; Stores ( prefix Sum , index ) as ( key , value ) mappings ; Iterate till N ; Update the prefixSum ; Update the length ; Put the latest index to find the minimum length ; Update the length ; Return the answer ; Function to find the length of the largest subarray ; Stores the sum of all array elements after modification ; Change greater than k to 1 ; Change smaller than k to - 1 ; Change equal to k to 0 ; Update total_sum ; No deletion required , return 0 ; Delete smallest subarray that has sum = total_sum ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class GFG { static int smallSubarray ( int [ ] arr , int n , int total_sum ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; int length = int . MaxValue ; int prefixSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { prefixSum += arr [ i ] ; if ( prefixSum == total_sum ) { length = Math . Min ( length , i + 1 ) ; } if ( m . ContainsKey ( prefixSum ) ) m [ prefixSum ] = i ; else m . Add ( prefixSum , i ) ; if ( m . ContainsKey ( prefixSum - total_sum ) ) { length = Math . Min ( length , i - m [ prefixSum - total_sum ] ) ; } } return length ; } static int smallestSubarrayremoved ( int [ ] arr , int n , int k ) { int total_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > k ) { arr [ i ] = 1 ; } else if ( arr [ i ] < k ) { arr [ i ] = - 1 ; } else { arr [ i ] = 0 ; } total_sum += arr [ i ] ; } if ( total_sum == 0 ) { return 0 ; } else { return smallSubarray ( arr , n , total_sum ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 12 , 16 , 12 , 13 , 10 } ; int K = 13 ; int n = arr . Length ; Console . WriteLine ( smallestSubarrayremoved ( arr , n , K ) ) ; } }
Balanced Ternary Number System | C # program to convert positive decimals into balanced ternary system ; Driver code
using System ; using System . Collections . Generic ; class GFG { static String balancedTernary ( int n ) { String output = " " ; while ( n > 0 ) { int rem = n % 3 ; n = n / 3 ; if ( rem == 2 ) { rem = - 1 ; n ++ ; } output = ( rem == 0 ? '0' : ( rem == 1 ) ? '1' : ' Z ' ) + output ; } return output ; } public static void Main ( String [ ] args ) { int n = 238 ; Console . Write ( " Equivalent ▁ Balanced ▁ Ternary ▁ of ▁ " + n + " ▁ is : ▁ " + balancedTernary ( n ) ) ; } }
Spt function or Smallest Parts Function of a given number | C # implementation to find the Spt Function to given number ; Variable to store spt function of a number ; Find the value of frequency of minimum element ; Function to add value of frequency of minimum element among all representations of n ; Find the value of frequency of minimum element ; Calculate spt ; Recursive function to find different ways in which n can be written as a sum of at one or more positive integers ; If sum becomes n , consider this representation ; Start from previous element in the representation till n ; Include current element from representation ; Call function again with reduced sum ; backtrack - remove current element from representation ; Function to find the spt function ; Using recurrence find different ways in which n can be written as a sum of at 1 or more positive integers ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int spt = 0 ; static int count ( List < int > arr , int min_i ) { int count = 0 ; for ( int i = 0 ; i < arr . Count ; i ++ ) if ( min_i == arr [ i ] ) count ++ ; return count ; } static void printList ( List < int > arr ) { int min_i = int . MaxValue ; for ( int i = 0 ; i < arr . Count ; i ++ ) min_i = Math . Min ( min_i , arr [ i ] ) ; int freq = count ( arr , min_i ) ; spt += freq ; } static void findWays ( List < int > arr , int i , int n ) { if ( n == 0 ) printList ( arr ) ; for ( int j = i ; j <= n ; j ++ ) { arr . Add ( j ) ; findWays ( arr , j , n - j ) ; arr . RemoveAt ( arr . Count - 1 ) ; } } static void spt_function ( int n ) { List < int > arr = new List < int > ( ) ; findWays ( arr , 1 , n ) ; Console . Write ( spt ) ; } public static void Main ( String [ ] args ) { int N = 4 ; spt_function ( N ) ; } }
Find initial integral solution of Linear Diophantine equation if finite solution exists | C # program for the above approach ; Function to implement the extended euclid algorithm ; Base Case ; Recursively find the gcd ; Function to print the solutions of the given equations ax + by = c ; Condition for infinite solutions ; Condition for no solutions exist ; Condition for no solutions exist ; Print the solution ; Driver Code ; Given coefficients ; Function call
using System ; class GFG { static int x , y ; static int gcd_extend ( int a , int b ) { if ( b == 0 ) { x = 1 ; y = 0 ; return a ; } else { int g = gcd_extend ( b , a % b ) ; int x1 = x , y1 = y ; x = y1 ; y = x1 - ( a / b ) * y1 ; return g ; } } static void print_solution ( int a , int b , int c ) { if ( a == 0 && b == 0 ) { if ( c == 0 ) { Console . Write ( " Infinite ▁ Solutions ▁ " + " Exist " + " STRNEWLINE " ) ; } else { Console . Write ( " No ▁ Solution ▁ exists " + " STRNEWLINE " ) ; } } int gcd = gcd_extend ( a , b ) ; if ( c % gcd != 0 ) { Console . Write ( " No ▁ Solution ▁ exists " + " STRNEWLINE " ) ; } else { Console . Write ( " x ▁ = ▁ " + x * ( c / gcd ) + " , ▁ y ▁ = ▁ " + y * ( c / gcd ) + " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int a , b , c ; a = 4 ; b = 18 ; c = 10 ; print_solution ( a , b , c ) ; } }
Count of pairs whose bitwise AND is a power of 2 | C # program for the above approach ; Method to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Function to return the number of valid pairs ; Iterate for all possible pairs ; Bitwise and value of the pair is passed ; Return the final count ; Driver Code ; Given array arr [ ] ; Function call
using System ; class GFG { static bool check ( int x ) { return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ; } static int count ( int [ ] arr , int n ) { int cnt = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( check ( arr [ i ] & arr [ j ] ) ) cnt ++ ; } } return cnt ; } public static void Main ( ) { int [ ] arr = new int [ ] { 6 , 4 , 2 , 3 } ; int n = arr . Length ; Console . Write ( count ( arr , n ) ) ; } }
Check if the Matrix follows the given constraints or not | C # implementation of the above approach ; Function checks if n is prime or not ; Corner case ; Check from 2 to Math . Sqrt ( n ) ; Function returns sum of all elements of matrix ; Stores the sum of the matrix ; Function to check if all a [ i , j ] with prime ( i + j ) are prime ; If index is prime ; If element not prime ; Driver code ; Check for both conditions
using System ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static int takeSum ( int [ , ] a ) { int sum = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) for ( int j = 0 ; j < 5 ; j ++ ) sum += a [ i , j ] ; return sum ; } static bool checkIndex ( int n , int m , int [ , ] a ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( isPrime ( i + j ) ) { if ( ! isPrime ( a [ i , j ] ) ) return false ; } } } return true ; } public static void Main ( String [ ] args ) { int n = 4 , m = 5 ; int [ , ] a = { { 1 , 2 , 3 , 2 , 2 } , { 2 , 2 , 7 , 7 , 7 } , { 7 , 7 , 21 , 7 , 10 } , { 2 , 2 , 3 , 6 , 7 } } ; int sum = takeSum ( a ) ; if ( isPrime ( sum ) && checkIndex ( n , m , a ) ) { Console . Write ( " YES " + " STRNEWLINE " ) ; } else { Console . Write ( " NO " + " STRNEWLINE " ) ; } } }
Count of all possible pairs of array elements with same parity | C # program for above approach ; Function to return the answer ; Generate all possible pairs ; Increment the count if both even or both odd ; Driver Code
using System ; class GFG { static int countPairs ( int [ ] A , int n ) { int count = 0 , i , j ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { if ( ( A [ i ] % 2 == 0 && A [ j ] % 2 == 0 ) || ( A [ i ] % 2 != 0 && A [ j ] % 2 != 0 ) ) count ++ ; } } return count ; } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 2 , 3 , 1 , 3 } ; int n = A . Length ; Console . Write ( countPairs ( A , n ) ) ; } }
Smallest number whose sum of digits is square of N | C # implementation of the above approach ; Function to return smallest number whose sum of digits is n ^ 2 ; Driver Code
using System ; class GFG { static int smallestNum ( int n ) { return ( int ) ( ( n * n % 9 + 1 ) * Math . Pow ( 10 , n * n / 9 ) - 1 ) ; } public static void Main ( String [ ] args ) { int n = 4 ; Console . Write ( smallestNum ( n ) ) ; } }
Second heptagonal numbers | C # implementation to find N - th term in the series ; Function to find N - th term in the series ; Driver code ; Function call
using System ; class GFG { static void findNthTerm ( int n ) { Console . Write ( n * ( 5 * n + 3 ) / 2 ) ; } public static void Main ( ) { int N = 4 ; findNthTerm ( N ) ; } }
Weakly Prime Numbers | C # program to check if n is Weakly Prime Number ; Function to check if N is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to check if n is a Weakly Prime Number ; Number should be prime ; Converting N to String ; Loop to change digit at every character one by one . ; Loop to store every digit one by one at index j ; 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 bool isWeaklyPrimeNum ( int N ) { if ( ! isPrime ( N ) ) return false ; String s = String . Join ( " " , N ) ; for ( int j = 0 ; j < s . Length ; j ++ ) { char [ ] str = s . ToCharArray ( ) ; for ( int i = 0 ; i <= 9 ; i ++ ) { char c = ( char ) ( '0' + i ) ; str [ j ] = c ; int Num = Int32 . Parse ( String . Join ( " " , str ) ) ; if ( str [ j ] != s [ j ] && isPrime ( Num ) ) { return false ; } } } return true ; } public static void Main ( String [ ] args ) { int n = 294001 ; if ( isWeaklyPrimeNum ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Unprimeable Numbers | C # program to check if n is unprimeable Number ; Function to check if N is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to check if n is a unprimeable Number ; Number should be composite ; Converting N to String ; Loop to change digit at every character one by one . ; Loop to store every digit one by one at index j ; Driver code ; Function Call
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 bool isUnPrimeableNum ( int N ) { if ( isPrime ( N ) ) return false ; String s = String . Join ( " " , N ) ; for ( int j = 0 ; j < s . Length ; j ++ ) { char [ ] str = s . ToCharArray ( ) ; for ( int i = 0 ; i <= 9 ; i ++ ) { char c = ( char ) ( '0' + i ) ; str [ j ] = c ; int Num = Int32 . Parse ( new String ( str ) ) ; if ( str [ j ] != s [ j ] && isPrime ( Num ) ) { return false ; } } } return true ; } public static void Main ( String [ ] args ) { int n = 200 ; if ( isUnPrimeableNum ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Find the Nth row in Pascal 's Triangle | C # program to find the Nth index row in Pascal 's triangle ; Function to find the elements of rowIndex in Pascal 's Triangle ; 1 st element of every row is 1 ; Check if the row that has to be returned is the first row ; Generate the previous row ; Generate the elements of the current row by the help of the previous row ; Return the row ; Driver code
using System ; using System . Collections . Generic ; class GFG { public static List < int > getRow ( int rowIndex ) { List < int > currow = new List < int > ( ) ; currow . Add ( 1 ) ; if ( rowIndex == 0 ) { return currow ; } List < int > prev = getRow ( rowIndex - 1 ) ; for ( int i = 1 ; i < prev . Count ; i ++ ) { int curr = prev [ i - 1 ] + prev [ i ] ; currow . Add ( curr ) ; } currow . Add ( 1 ) ; return currow ; } public static void Main ( String [ ] args ) { int n = 3 ; List < int > arr = getRow ( n ) ; for ( int i = 0 ; i < arr . Count ; i ++ ) { if ( i == arr . Count - 1 ) Console . Write ( arr [ i ] ) ; else Console . Write ( arr [ i ] + " , ▁ " ) ; } } }
All possible values of floor ( N / K ) for all values of K | C # program for the above approach ; Function to print all possible values of Math . floor ( N / K ) ; Loop from 1 to N + 1 ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void allQuotients ( int N ) { SortedSet < int > s = new SortedSet < int > ( ) ; for ( int k = 1 ; k <= N + 1 ; k ++ ) { s . Add ( N / k ) ; } foreach ( int it in s ) { Console . Write ( it + " ▁ " ) ; } } static void Main ( ) { int N = 5 ; allQuotients ( N ) ; } }
Greatest odd factor of an even number | C # program for the above approach ; Function to print greatest odd factor ; Initialize i with 1 ; Iterate till i <= pow_2 ; Find the pow ( 2 , i ) ; If factor is odd , then print the number and break ; Driver code ; Given number ; Function call
using System ; class GFG { public static int greatestOddFactor ( int n ) { int pow_2 = ( int ) ( Math . Log ( n ) ) ; int i = 1 ; while ( i <= pow_2 ) { int fac_2 = ( 2 * i ) ; if ( n % fac_2 == 0 ) { if ( ( n / fac_2 ) % 2 == 1 ) { return ( n / fac_2 ) ; } } i += 1 ; } return 0 ; } public static void Main ( String [ ] args ) { int N = 8642 ; Console . WriteLine ( greatestOddFactor ( N ) ) ; } }
Find the element in a linked list with frequency at least N / 3 | C # program to find an element with frequency of at least N / 3 in a linked list ; Structure of a node for the linked list ; Utility function to create a node ; Function to find and return the element with frequency of at least N / 3 ; Candidates for being the required majority element ; Store the frequencies of the respective candidates ; Iterate all nodes ; Increase frequency of candidate s ; Increase frequency of candidate t ; Set the new sting as candidate for majority ; Set the new sting as second candidate for majority ; Decrease the frequency ; Check the frequency of two final selected candidate linklist ; Increase the frequency of first candidate ; Increase the frequency of second candidate ; Return the string with higher frequency ; Driver Code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { class node { public string i ; public node next = null ; } ; static node newnode ( string s ) { node temp = new node ( ) ; temp . i = s ; temp . next = null ; return temp ; } static string Majority_in_linklist ( node head ) { string s = " " ; string t = " " ; int p = 0 , q = 0 ; node ptr = null ; while ( head != null ) { if ( s . Equals ( head . i ) ) { p = p + 1 ; } else { if ( t . Equals ( head . i ) ) { q = q + 1 ; } else { if ( p == 0 ) { s = head . i ; p = 1 ; } else { if ( q == 0 ) { t = head . i ; q = 1 ; } else { p = p - 1 ; q = q - 1 ; } } } } head = head . next ; } head = ptr ; p = 0 ; q = 0 ; while ( head != null ) { if ( s . Equals ( head . i ) ) { p = 1 ; } else { if ( t . Equals ( head . i ) ) { q = 1 ; } } head = head . next ; } if ( p > q ) { return s ; } else { return t ; } } public static void Main ( string [ ] arg ) { node head = newnode ( " geeks " ) ; head . next = newnode ( " geeks " ) ; head . next . next = newnode ( " abcd " ) ; head . next . next . next = newnode ( " game " ) ; head . next . next . next . next = newnode ( " game " ) ; head . next . next . next . next . next = newnode ( " knight " ) ; head . next . next . next . next . next . next = newnode ( " harry " ) ; head . next . next . next . next . next . next . next = newnode ( " geeks " ) ; Console . Write ( Majority_in_linklist ( head ) ) ; } }
Form smallest number using indices of numbers chosen from Array with sum less than S | C # implementation to find minimum number which have a maximum length ; Function to find the minimum number which have maximum length ; Find Maximum length of number ; Find minimum number WHich have maximum length ; Driver Code
using System ; using System . Text ; class GFG { static String max_number ( int [ ] arr , int sum ) { int [ ] frac = new int [ 9 ] ; int maxi = int . MinValue ; StringBuilder ans = new StringBuilder ( ) ; int pos = 0 ; for ( int i = 0 ; i < 9 ; i ++ ) { frac [ i ] = sum / arr [ i ] ; if ( frac [ i ] > maxi ) { pos = i ; maxi = frac [ i ] ; } } for ( int i = 0 ; i < maxi ; i ++ ) { ans . Append ( ( char ) ( ( pos + 1 ) + '0' ) ) ; } sum -= maxi * arr [ pos ] ; for ( int i = 0 ; i < maxi ; i ++ ) { for ( int j = 1 ; j <= 9 ; j ++ ) { if ( sum + arr [ pos ] - arr [ j - 1 ] >= 0 ) { ans [ i ] = ( char ) ( j + '0' ) ; sum += arr [ pos ] - arr [ j - 1 ] ; break ; } } } if ( maxi == 0 ) { return "0" ; } else { return ans . ToString ( ) ; } } public static void Main ( String [ ] str ) { int [ ] arr = { 3 , 4 , 2 , 4 , 6 , 5 , 4 , 2 , 3 } ; int s = 13 ; Console . WriteLine ( max_number ( arr , s ) ) ; } }
Check if given intervals can be made non | C # implementation to check if the intervals can be non - overlapping by by adding or subtracting X to each interval ; Function to check if two intervals overlap with each other ; Condition to check if the intervals overlap ; Function to check if there is a existing overlapping intervals ; Path compression ; Union of two intervals Returns True if there is a overlapping with the same another interval ; Both have same another overlapping interval ; Function to check if the intervals can be added by X to form non - overlapping intervals ; If the intervals overlaps we will union them ; There is no cycle ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static bool checkOverlapping ( List < int > a , List < int > b ) { if ( a [ 0 ] < b [ 0 ] ) { int temp = a [ 0 ] ; a [ 0 ] = b [ 0 ] ; b [ 0 ] = temp ; temp = a [ 1 ] ; a [ 1 ] = b [ 1 ] ; b [ 1 ] = temp ; } if ( b [ 0 ] <= a [ 0 ] && a [ 0 ] <= b [ 1 ] ) return true ; return false ; } static int find ( List < int > a , int i ) { if ( a [ i ] == i ) { return i ; } a [ i ] = find ( a , a [ i ] ) ; return a [ i ] ; } static bool union ( List < int > a , int x , int y ) { int xs = find ( a , x ) ; int ys = find ( a , y ) ; if ( xs == ys ) { return true ; } a [ ys ] = xs ; return false ; } static bool checkNonOverlapping ( List < List < int > > arr , int n ) { List < int > dsu = new List < int > ( ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) { dsu . Add ( i ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( checkOverlapping ( arr [ i ] , arr [ j ] ) ) { if ( union ( dsu , i , j ) ) { return false ; } } } } return true ; } static void Main ( ) { List < List < int > > arr = new List < List < int > > ( ) ; arr . Add ( new List < int > { 1 , 4 } ) ; arr . Add ( new List < int > { 2 , 2 } ) ; arr . Add ( new List < int > { 2 , 3 } ) ; int n = arr . Count ; if ( checkNonOverlapping ( arr , n ) ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }
Number formed after K times repeated addition of smallest divisor of N | C # program to find the Kth number formed after repeated addition of smallest divisor of N ; If N is even ; If N is odd ; Add smallest divisor to N ; Updated N is even ; Driver code
using System ; class GFG { static void FindValue ( int N , int K ) { if ( N % 2 == 0 ) { N = N + 2 * K ; } else { int i ; for ( i = 2 ; i < Math . Sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) break ; } N = N + i ; N = N + 2 * ( K - 1 ) ; } Console . WriteLine ( N ) ; } public static void Main ( ) { int N = 9 ; int K = 4 ; FindValue ( N , K ) ; } }
Find last digit in factorial | C # program to find last digit in factorial n . ; Explicitly handle all numbers less than or equal to 4 ; For all numbers greater than 4 the last digit is 0 ; Driver code
using System ; class GFG { static int lastDigitFactorial ( int n ) { if ( n == 0 ) return 1 ; else if ( n <= 2 ) return n ; else if ( n == 3 ) return 6 ; else if ( n == 4 ) return 4 ; else return 0 ; } public static void Main ( string [ ] args ) { Console . Write ( lastDigitFactorial ( 6 ) ) ; } }
Program to convert Hexa | C # implementation to convert the given HexaDecimal number to its equivalent BCD . ; Function to convert HexaDecimal to its BCD ; Iterating through the digits ; check whether s [ i ] is a character or a integer between 0 to 9 and compute its equivalent BCD ; Driver Code ; Function Call
using System ; class GFG { static void HexaDecimaltoBCD ( string s ) { int len = s . Length ; for ( int i = 0 ; i <= len - 1 ; i ++ ) { if ( s [ i ] >= 47 && s [ i ] <= 52 ) { string result = Convert . ToString ( ( int ) s [ i ] , 2 ) ; Console . Write ( result . Substring ( result . Length - 4 ) + " ▁ " ) ; } else { string result = Convert . ToString ( ( int ) s [ i ] - 55 , 2 ) ; Console . Write ( result . Substring ( result . Length - 4 ) + " ▁ " ) ; } } } static void Main ( ) { string s = "11F " ; HexaDecimaltoBCD ( s ) ; } }
Find the sum of the first Nth Heptadecagonal Number | C # program to find the sum of the first N heptadecagonal numbers ; Function to find the N - th heptadecagonal number ; Formula to calculate nth heptadecagonal number ; Function to find the sum of the first N heptadecagonal numbers ; Variable to store the sum ; Iterating from 1 to N ; Finding the sum ; Driver code
using System ; class GFG { public static int heptadecagonal_num ( int n ) { return ( ( 15 * n * n ) - 13 * n ) / 2 ; } public static int sum_heptadecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += heptadecagonal_num ( i ) ; } return summ ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( sum_heptadecagonal_num ( n ) ) ; } }
Program to check if N is a Centered Pentagonal Number or not | C # program for the above approach ; Function to check if number N is a centered pentagonal number ; Condition to check if N is a centered pentagonal number ; Driver Code ; Given number ; Function call
using System ; class GFG { static bool isCenteredpentagonal ( int N ) { float n = ( float ) ( ( 5 + Math . Sqrt ( 40 * N - 15 ) ) / 10 ) ; return ( n - ( int ) n ) == 0 ; } public static void Main ( string [ ] args ) { int N = 6 ; if ( isCenteredpentagonal ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Program to check if N is a Dodecagonal Number | C # program for the above approach ; Function to check if number N is a dodecagonal number or not ; Condition to check if the N is a dodecagonal number ; Driver Code ; Given number ; Function call
using System ; class GFG { static bool isdodecagonal ( int N ) { float n = ( float ) ( ( 4 + Math . Sqrt ( 20 * N + 16 ) ) / 10 ) ; return ( n - ( int ) n ) == 0 ; } public static void Main ( string [ ] args ) { int N = 12 ; if ( isdodecagonal ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }