codeparrot/xlcost-text-to-code huggingface dataset:
Program to find HCF ( Highest Common Factor ) of 2 Numbers | C # program to find GCD of two numbers ; Recursive function to return gcd of a and b ; Driver method
using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static void Main ( ) { int a = 98 , b = 56 ; Console . WriteLine ( " GCD ▁ of ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + gcd ( a , b ) ) ; } }
Largest number with maximum trailing nines which is less than N and greater than N | C # code to implement above function ; It 's better to use long to handle big integers function to count no. of digits ; function to implement above approach ; if difference between power and n doesn 't exceed d ; loop to build a number from the appropriate no of digits containing only 9 ; if the build number is same as original number ( n ) ; observation ; Driver Code ; variable that stores no . of digits in n
using System ; class GFG { static long dig ( long a ) { long count = 0 ; while ( a > 0 ) { a /= 10 ; count ++ ; } return count ; } static void required_number ( long num , long n , long d ) { long i , j , power = 1 , a , flag = 0 ; for ( i = num ; i >= 1 ; i -- ) { power = ( long ) Math . Pow ( 10 , i ) ; a = n % power ; if ( d > a ) { flag = 1 ; break ; } } if ( flag > 0 ) { long t = 0 ; for ( j = 0 ; j < i ; j ++ ) { t += ( long ) ( 9 * Math . Pow ( 10 , j ) ) ; } if ( n % power == t ) Console . Write ( n ) ; else { Console . Write ( n - ( n % power ) - 1 ) ; } } else Console . Write ( n ) ; } public static void Main ( ) { long n = 1029 , d = 102 ; long num = dig ( n ) ; required_number ( num , n , d ) ; } }
Egg Dropping Puzzle with 2 Eggs and K Floors | C # program to find optimal number of trials for k floors and 2 eggs . ; Driver code
class GFG { static int twoEggDrop ( int k ) { return ( int ) System . Math . Ceiling ( ( - 1.0 + System . Math . Sqrt ( 1 + 8 * k ) ) / 2.0 ) ; } public static void Main ( ) { int k = 100 ; System . Console . WriteLine ( twoEggDrop ( k ) ) ; } }
Program to find the Area and Volume of Icosahedron | C # program to find the Area and volume of Icosahedron ; Function to find area of Icosahedron ; Formula to calculating area ; Function to find volume of Icosahedron ; Formula to calculating volume ; Driver code ; Function call to find area of Icosahedron . ; Function call to find volume of Icosahedron .
using System ; public class GFG { static float findArea ( float a ) { float area ; area = ( float ) ( 5 * Math . Sqrt ( 3 ) * a * a ) ; return area ; } static float findVolume ( float a ) { float volume ; volume = ( float ) ( ( ( float ) 5 / 12 ) * ( 3 + Math . Sqrt ( 5 ) ) * a * a * a ) ; return volume ; } static public void Main ( ) { float a = 5 ; Console . WriteLine ( " Area : ▁ " + findArea ( a ) ) ; Console . WriteLine ( " Volume : ▁ " + findVolume ( a ) ) ; } }
Total number of ways to place X and Y at n places such that no two X are together | C # program to find the number of ways . Calculate total ways to place ' x ' and ' y ' at n places such that no two ' x ' are together ; Function to return number of ways ; for n = 1 ; for n = 2 ; iterate to find Fibonacci term ; Driver Code ; total number of places
using System ; class GFG { static int ways ( int n ) { int first = 2 ; int second = 3 ; int res = 0 ; for ( int i = 3 ; i <= n ; i ++ ) { res = first + second ; first = second ; second = res ; } return res ; } static public void Main ( ) { int n = 7 ; Console . WriteLine ( " Total ▁ ways ▁ are : ▁ " + ways ( n ) ) ; } }
Number of digits in N factorial to the power N | C # program to find count of digits in N factorial raised to N ; we take sum of logarithms as explained in the approach ; multiply the result with n ; Driver Code
using System ; class GFG { static int countDigits ( int n ) { double ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) ans += Math . Log10 ( i ) ; ans = ans * n ; return 1 + ( int ) Math . Floor ( ans ) ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( countDigits ( n ) + " STRNEWLINE " ) ; } }
Program to convert centimeter into meter and kilometer | C # program to convert centimeter into meter and kilometer ; Driver Code ; Converting centimeter into meter and kilometer
using System ; class GFG { static public void Main ( ) { double cm , meter , kilometer ; cm = 1000 ; meter = cm / 100.0 ; kilometer = cm / 100000.0 ; Console . WriteLine ( " Length ▁ in ▁ " + " meter ▁ = ▁ " + meter + " m " ) ; Console . WriteLine ( " Length ▁ in ▁ " + " Kilometer ▁ = ▁ " + kilometer + " km " ) ; } }
Check if two people starting from different points ever meet | C # program to find if two people starting from different positions ever meet or not . ; If speed of a person at a position before other person is smaller , then return false . ; Making sure that x1 is greater ; checking if relative speed is a factor of relative distance or not ;  ; Driver code
using System ; public class GFG { static bool everMeet ( int x1 , int x2 , int v1 , int v2 ) { if ( x1 < x2 && v1 <= v2 ) { return false ; } if ( x1 > x2 && v1 >= v2 ) { return false ; } if ( x1 < x2 ) { swap ( x1 , x2 ) ; swap ( v1 , v2 ) ; } return ( ( x1 - x2 ) % ( v1 - v2 ) == 0 ) ; } static void swap ( int a , int b ) { int t = a ; a = b ; b = t ; } public static void Main ( ) { int x1 = 5 , v1 = 8 , x2 = 4 , v2 = 7 ; if ( everMeet ( x1 , x2 , v1 , v2 ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Count of distinct GCDs among all the non | C # program for the above approach ;  ; Function to calculate the number of distinct GCDs among all non - empty subsequences of an array ; Variables to store the largest element in array and the required count ; Map to store whether a number is present in A ; Calculate largest number in A and mapping A to Mp ; Iterate over all possible values of GCD ; Variable to check current GCD ; Iterate over all multiples of i ; If j is present in A ; Calculate gcd of all encountered multiples of i ; Current GCD is possible ; Return answer ; Driver code ; Input ; Function calling
using System ; using System . Collections . Generic ; class GFG { static int gcd ( int a , int b ) { return b == 0 ? a : gcd ( b , a % b ) ; } static int distinctGCDs ( int [ ] arr , int N ) { int M = - 1 , ans = 0 ; Dictionary < int , int > Mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { M = Math . Max ( M , arr [ i ] ) ; if ( Mp . ContainsKey ( arr [ i ] ) ) Mp [ arr [ i ] ] = 1 ; else Mp . Add ( arr [ i ] , 1 ) ; } for ( int i = 1 ; i <= M ; i ++ ) { int currGcd = 0 ; for ( int j = i ; j <= M ; j += i ) { if ( Mp . ContainsKey ( j ) ) { currGcd = gcd ( currGcd , j ) ; if ( currGcd == i ) { ans ++ ; break ; } } } } return ans ; } public static void Main ( ) { int [ ] arr = { 3 , 11 , 14 , 6 , 12 } ; int N = arr . Length ; Console . Write ( distinctGCDs ( arr , N ) ) ; } }
Find ceil of a / b without using ceil ( ) function | C # program to find ceil ( a / b ) without using ceil ( ) function ; Driver Code ; taking input 1 ; example of perfect division taking input 2
using System ; class GFG { public static void Main ( ) { int a = 4 ; int b = 3 ; int val = ( a + b - 1 ) / b ; Console . WriteLine ( " The ▁ ceiling " + " ▁ value ▁ of ▁ 4/3 ▁ is ▁ " + val ) ; a = 6 ; b = 3 ; val = ( a + b - 1 ) / b ; Console . WriteLine ( " The ▁ ceiling " + " ▁ value ▁ of ▁ 6/3 ▁ is ▁ " + val ) ; } }
Sum of range in a series of first odd then even natural numbers | C # program to find sum in the given range in the sequence 1 3 5 7. ... . N 2 4 6. . . N - 1 ; Function that returns sum in the range 1 to x in the sequence 1 3 5 7. ... . N 2 4 6. . . N - 1 ; number of odd numbers ; number of extra even numbers required ; Driver code
using System ; public class GFG { static double sumTillX ( double x , double n ) { double odd = Math . Ceiling ( n / 2.0 ) ; if ( x <= odd ) return x * x ; double even = x - odd ; return ( ( odd * odd ) + ( even * even ) + even ) ; } static double rangeSum ( double N , double L , double R ) { return sumTillX ( R , N ) - sumTillX ( L - 1 , N ) ; } public static void Main ( ) { long N = 10 , L = 1 , R = 6 ; Console . Write ( rangeSum ( N , L , R ) ) ; } }
Twin Prime Numbers between 1 and n | C # program to illustrate . . print all twin primes Using Sieve of Eratosthenes ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; check for twin prime numbers To display th result ; Driver Code ; calling the function
using System ; public class GFG { public static void printtwinprime ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int i = 2 ; i <= n - 2 ; i ++ ) { if ( prime [ i ] == true && prime [ i + 2 ] == true ) Console . Write ( " ▁ ( " + i + " , ▁ " + ( i + 2 ) + " ) " ) ; } } public static void Main ( ) { int n = 25 ; printtwinprime ( n ) ; } }
Cube Free Numbers smaller than n | C # Program to print all cube free numbers smaller than or equal to n . ; Returns true if n is a cube free number , else returns false . ; check for all possible divisible cubes ; Print all cube free numbers smaller than n . ; Driver program
using System ; class GFG { static bool isCubeFree ( int n ) { if ( n == 1 ) return false ; for ( int i = 2 ; i * i * i <= n ; i ++ ) if ( n % ( i * i * i ) == 0 ) return false ; return true ; } static void printCubeFree ( int n ) { for ( int i = 2 ; i <= n ; i ++ ) { if ( isCubeFree ( i ) ) { Console . Write ( i + " ▁ " ) ; } } } public static void Main ( ) { int n = 20 ; printCubeFree ( n ) ; } }
Decimal Equivalent of Gray Code and its Inverse | C # Program to convert given decimal number of gray code into its inverse in decimal form ; Function to convert given decimal number of gray code into its inverse in decimal form ; Taking xor until n becomes zero ; Driver code
using System ; class GFG { static int inversegrayCode ( int n ) { int inv = 0 ; for ( ; n != 0 ; n = n >> 1 ) inv ^= n ; return inv ; } public static void Main ( ) { int n = 15 ; Console . Write ( inversegrayCode ( n ) ) ; } }
Product of unique prime factors of a number | C # program to find product of unique prime factors of a number . ; Function to find product of prime factors ; Handle prime factor 2 explicitly so that can optimally handle other prime factors . ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; While i divides n , print i and divide n ; This condition is to handle the case when n is a prime number greater than 2 ; Driver Code
using System ; public class GFG { public static long productPrimeFactors ( int n ) { long product = 1 ; if ( n % 2 == 0 ) { product *= 2 ; while ( n % 2 == 0 ) n = n / 2 ; } for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { product = product * i ; while ( n % i == 0 ) n = n / i ; } } if ( n > 2 ) product = product * n ; return product ; } public static void Main ( String [ ] args ) { int n = 44 ; Console . Write ( productPrimeFactors ( n ) ) ; } }
Maximizing Probability of one type from N containers | C # program to find maximum probability of getting a copy ' A ' from N ; Returns the Maximum probability for Drawing 1 copy of number A from N containers with N copies each of numbers A and B ; Pmax = N / ( N + 1 ) ; Driver code ; 1. N = 1 ; 2. N = 2 ; 3. N = 10
using System ; class GFG { static double calculateProbability ( int N ) { double probability = ( double ) N / ( N + 1 ) ; return probability ; } public static void Main ( ) { int N ; double probabilityMax ; N = 1 ; probabilityMax = calculateProbability ( N ) ; Console . WriteLine ( " Maximum ▁ Probability ▁ for ▁ N ▁ = ▁ " + N + " ▁ is , ▁ " + Math . Round ( probabilityMax * 10000.0 ) / 10000.0 ) ; N = 2 ; probabilityMax = calculateProbability ( N ) ; Console . WriteLine ( " Maximum ▁ Probability ▁ for ▁ N ▁ = ▁ " + N + " ▁ is , ▁ " + Math . Round ( probabilityMax * 10000.0 ) / 10000.0 ) ; N = 10 ; probabilityMax = calculateProbability ( N ) ; Console . WriteLine ( " Maximum ▁ Probability ▁ for ▁ N ▁ = ▁ " + N + " ▁ is , ▁ " + Math . Round ( probabilityMax * 10000.0 ) / 10000.0 ) ; } }
Program to implement standard deviation of grouped data | C # program to implement standard deviation of grouped data . ; Function to find mean of grouped data . ; Function to find standard deviation of grouped data . ; Formula to find standard deviation deviation of grouped data . ; Driver function . ; Declare and initialize the lower limit of interval . ; Declare and initialize the upper limit of interval . ; Calculating the size of array .
using System ; class GFG { static float mean ( float [ ] mid , int [ ] freq , int n ) { float sum = 0 , freqSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + mid [ i ] * freq [ i ] ; freqSum = freqSum + freq [ i ] ; } return sum / freqSum ; } static float groupedSD ( float [ ] lower_limit , float [ ] upper_limit , int [ ] freq , int n ) { float [ ] mid = new float [ n ] ; float sum = 0 , freqSum = 0 , sd ; for ( int i = 0 ; i < n ; i ++ ) { mid [ i ] = ( lower_limit [ i ] + upper_limit [ i ] ) / 2 ; sum = sum + freq [ i ] * mid [ i ] * mid [ i ] ; freqSum = freqSum + freq [ i ] ; } sd = ( float ) Math . Sqrt ( ( sum - freqSum * mean ( mid , freq , n ) * mean ( mid , freq , n ) ) / ( freqSum - 1 ) ) ; return sd ; } public static void Main ( ) { float [ ] lower_limit = { 50 , 61 , 71 , 86 , 96 } ; float [ ] upper_limit = { 60 , 70 , 85 , 95 , 100 } ; int [ ] freq = { 9 , 7 , 9 , 12 , 8 } ; int n = lower_limit . Length ; Console . WriteLine ( groupedSD ( lower_limit , upper_limit , freq , n ) ) ; } }
Average of first n even natural numbers | C # implementation to find Average of sum of first n natural even number ; function to find average of sum of first n even numbers ; sum of first n even numbers ; calculating Average ; driver code
using System ; class GFG { static int avg_of_even_num ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += 2 * i ; return ( sum / n ) ; } public static void Main ( ) { int n = 9 ; Console . Write ( avg_of_even_num ( n ) ) ; } }
Average of first n even natural numbers | C # Program to find the average of sum of first n even numbers ; Return the average of sum of first n even numbers ; driver code
using System ; class GFG { static int avg_of_even_num ( int n ) { return n + 1 ; } public static void Main ( ) { int n = 8 ; Console . Write ( avg_of_even_num ( n ) ) ; } }
Program to find simple moving average | C # program to calculate Simple Moving Average ; queue used to store list so that we get the average ; constructor to initialize period ; function to add new data in the list and update the sum so that we get the new mean ; Updating size so that length of data set should be equal to period as a normal mean has ; function to calculate mean ; Driver code
using System ; using System . Collections . Generic ; public class SimpleMovingAverage { private Queue < Double > Dataset = new Queue < Double > ( ) ; private int period ; private double sum ; public SimpleMovingAverage ( int period ) { this . period = period ; } public void addData ( double num ) { sum += num ; Dataset . Enqueue ( num ) ; if ( Dataset . Count > period ) { sum -= Dataset . Dequeue ( ) ; } } public double getMean ( ) { return sum / period ; } public static void Main ( String [ ] args ) { double [ ] input_data = { 1 , 3 , 5 , 6 , 8 , 12 , 18 , 21 , 22 , 25 } ; int per = 3 ; SimpleMovingAverage obj = new SimpleMovingAverage ( per ) ; foreach ( double x in input_data ) { obj . addData ( x ) ; Console . WriteLine ( " New ▁ number ▁ added ▁ is ▁ " + x + " , ▁ SMA ▁ = ▁ " + obj . getMean ( ) ) ; } } }
Sum of square of first n odd numbers | Efficient C # method to find sum of square of first n odd numbers . ; driver code
using System ; class GFG { static int squareSum ( int n ) { return n * ( 4 * n * n - 1 ) / 3 ; } public static void Main ( ) { Console . Write ( squareSum ( 8 ) ) ; } }
Check whether given three numbers are adjacent primes | Java program to check given three numbers are primes are not . ; Function checks whether given number is prime or not . ; check if n is a multiple of 2 ; if not , then just check the odds ; return next prime number ; start with next number . ; breaks after finding next prime number ; check given three numbers are adjacent primes are not . ; check given three numbers are primes are not . ; find next prime of a ; If next is not same as ' a ' ; If next next is not same as ' c ' ; Driver code
using System ; class GFG { public static bool isPrime ( int n ) { if ( n % 2 == 0 ) return false ; for ( int i = 3 ; i * i <= n ; i += 2 ) if ( n % i == 0 ) return false ; return true ; } public static int nextPrime ( int start ) { int next = start + 1 ; while ( ! isPrime ( next ) ) next ++ ; return next ; } public static bool areAdjacentPrimes ( int a , int b , int c ) { if ( ! isPrime ( a ) || ! isPrime ( b ) || ! isPrime ( c ) ) return false ; int next = nextPrime ( a ) ; if ( next != b ) return false ; if ( nextPrime ( b ) != c ) return false ; return true ; } public static void Main ( ) { if ( areAdjacentPrimes ( 11 , 13 , 19 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check whether a number is semiprime or not | C # Program to check whether number is semiprime or not ; Utility function to check whether number is semiprime or not ; If number is greater than 1 , add it to the count variable as it indicates the number remain is prime number ; Return '1' if count is equal to '2' else return '0' ; Function to print ' True ' or ' False ' according to condition of semiprime ; Driver code
using System ; class GFG { static int checkSemiprime ( int num ) { int cnt = 0 ; for ( int i = 2 ; cnt < 2 && i * i <= num ; ++ i ) while ( num % i == 0 ) { num /= i ; ++ cnt ; } if ( num > 1 ) ++ cnt ; return cnt == 2 ? 1 : 0 ; } static void semiprime ( int n ) { if ( checkSemiprime ( n ) != 0 ) Console . WriteLine ( " True " ) ; else Console . WriteLine ( " False " ) ; } public static void Main ( ) { int n = 6 ; semiprime ( n ) ; n = 8 ; semiprime ( n ) ; } }
Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n | C # Program to find sum of series 1 + 2 + 2 + 3 + . . . + n ; Function that find sum of series . ; Driver Code ; Function call
using System ; class GfG { static int sumOfSeries ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum = sum + i * i ; return sum ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( sumOfSeries ( n ) ) ; } }
Program to find sum of series 1 + 2 + 2 + 3 + 3 + 3 + . . . + n | C # Program to find sum of series 1 + 2 + 2 + 3 + . . . + n ; Function that find sum of series . ; Driver Code
using System ; public class GfG { static int sumOfSeries ( int n ) { return ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( sumOfSeries ( n ) ) ; } }
Maximum binomial coefficient term value | C # Program to find maximum binomial coefficient term ; Returns value of Binomial Coefficient C ( n , k ) ; Calculate value of Binomial Coefficient in bottom up manner ; Base Cases ; Calculate value using previously stored values ; Return maximum binomial coefficient term value . ; if n is even ; if n is odd ; Driven Program
using System ; public class GFG { static int binomialCoeff ( int n , int k ) { int [ , ] C = new int [ n + 1 , k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= Math . Min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i , j ] = 1 ; else C [ i , j ] = C [ i - 1 , j - 1 ] + C [ i - 1 , j ] ; } } return C [ n , k ] ; } static int maxcoefficientvalue ( int n ) { if ( n % 2 == 0 ) return binomialCoeff ( n , n / 2 ) ; else return binomialCoeff ( n , ( n + 1 ) / 2 ) ; } static public void Main ( ) { int n = 4 ; Console . WriteLine ( maxcoefficientvalue ( n ) ) ; } }
Smallest n digit number divisible by given three numbers | C # program to find smallest n digit number which is divisible by x , y and z . ;  ; LCM for x , y , z ; returns smallest n digit number divisible by x , y and z ; find the LCM ; find power of 10 for least number ; reminder after ; If smallest number itself divides lcm . ; add lcm - reminder number for next n digit number ; this condition check the n digit number is possible or not if it is possible it return the number else return 0 ; Driver code ; if number is possible then it print the number
using System ; public class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) { return a ; } else { return __gcd ( b , a % b ) ; } } static int LCM ( int x , int y , int z ) { int ans = ( ( x * y ) / ( __gcd ( x , y ) ) ) ; return ( ( z * ans ) / ( __gcd ( ans , z ) ) ) ; } static int findDivisible ( int n , int x , int y , int z ) { int lcm = LCM ( x , y , z ) ; int ndigitnumber = ( int ) Math . Pow ( 10 , n - 1 ) ; int reminder = ndigitnumber % lcm ; if ( reminder == 0 ) return ndigitnumber ; ndigitnumber += lcm - reminder ; if ( ndigitnumber < Math . Pow ( 10 , n ) ) return ndigitnumber ; else return 0 ; } static public void Main ( ) { int n = 4 , x = 2 , y = 3 , z = 5 ; int res = findDivisible ( n , x , y , z ) ; if ( res != 0 ) Console . WriteLine ( res ) ; else Console . WriteLine ( " Not ▁ possible " ) ; } }
Sum of squares of first n natural numbers | C # Program to find sum of square of first n natural numbers . This program avoids overflow upto some extent for large value of n . ; Return the sum of square of first n natural numbers ; Driver Code
using System ; class GFG { public static int squaresum ( int n ) { return ( n * ( n + 1 ) / 2 ) * ( 2 * n + 1 ) / 3 ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( squaresum ( n ) ) ; } }
Program to calculate distance between two points | C # code to compute distance ; Function to calculate distance ; Calculating distance ; Driver code
using System ; class GFG { static double distance ( int x1 , int y1 , int x2 , int y2 ) { return Math . Sqrt ( Math . Pow ( x2 - x1 , 2 ) + Math . Pow ( y2 - y1 , 2 ) * 1.0 ) ; } public static void Main ( ) { Console . WriteLine ( Math . Round ( distance ( 3 , 4 , 4 , 3 ) * 100000.0 ) / 100000.0 ) ; } }
Check if a large number is divisibility by 15 | C # program to check if a large number is divisible by 15 ; function to check if a large number is divisible by 15 ; length of string ; check divisibility by 5 ; Sum of digits ; if divisible by 3 ; Driver code
using System ; class GFG { public static bool isDivisible ( String S ) { int n = S . Length ; if ( S [ n - 1 ] != '5' && S [ n - 1 ] != '0' ) return false ; int sum = 0 ; for ( int i = 0 ; i < S . Length ; i ++ ) sum += ( int ) S [ i ] ; if ( sum % 3 == 0 ) return true ; else return false ; } public static void Main ( ) { String S = "15645746327462384723984023940239" ; if ( isDivisible ( S ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; String S1 = "15645746327462384723984023940235" ; if ( isDivisible ( S1 ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }