codeparrot/xlcost-text-to-code huggingface dataset:
Number of Digits in a ^ b | C # Program to calculate no . of digits in a ^ b ; function to calculate number of digits in a ^ b ; driver program
using System ; class GFG { static int no_of_digit ( int a , int b ) { return ( ( int ) ( b * Math . Log10 ( a ) ) + 1 ) ; } public static void Main ( ) { int a = 2 , b = 100 ; Console . Write ( " no . ▁ of ▁ digits ▁ = ▁ " + no_of_digit ( a , b ) ) ; } }
Check whether a number is Emirpimes or not | C # code to check whether a number is Emirpimes or not ; Checking whether a number is semi - prime or not ; Increment count of prime numbers ; If number is still greater than 1 , after exiting the for loop add it to the count variable as it indicates the number is a prime number ; Return '1' if count is equal to '2' else return '0' ; Checking whether a number is emirpimes or not ; Number itself is not semiprime . ; Finding reverse of n . ; The definition of emirpimes excludes palindromes , hence we do not check further , if the number entered is a palindrome ; Checking whether the reverse of the semi prime number entered is also a semi prime number or not ; Driver Code
using System ; class GFG { static bool 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 ; } static bool isEmirpimes ( int n ) { if ( checkSemiprime ( n ) == false ) return false ; int r = 0 ; for ( int t = n ; t != 0 ; t = t / n ) r = r * 10 + t % 10 ; if ( r == n ) return false ; return ( checkSemiprime ( r ) ) ; } public static void Main ( ) { int n = 15 ; if ( isEmirpimes ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Connell Sequence | C # code to generate first ' n ' terms of Connell Sequence ; Function to generate a fixed number of even or odd terms . The size of r decides whether numbers to be generated even or odd . ; Generating the first ' n ' terms of Connell Sequence ; A dummy 0 is inserted at the beginning for consistency ; Calling function gen ( ) to generate ' k ' number of terms ; Checking if ' n ' terms are already generated ; Removing the previously inserted dummy 0 ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static List < long > gen ( long n , List < long > r ) { long a = r [ r . Count - 1 ] ; a ++ ; for ( int i = 1 ; i <= n ; a += 2 , i ++ ) r . Add ( a ) ; return r ; } static List < long > conell ( long n ) { List < long > res = new List < long > ( ) ; long k = 1 ; res . Add ( 0 ) ; while ( true ) { res = gen ( k , res ) ; k ++ ; int j = res . Count - 1 ; while ( j != n && j + k > n ) k -- ; if ( j >= n ) break ; } res . RemoveAt ( 0 ) ; return res ; } static void Main ( ) { long n = 10 ; Console . WriteLine ( " The ▁ first ▁ " + n + " ▁ terms ▁ are " ) ; List < long > res = conell ( n ) ; for ( int i = 0 ; i < res . Count ; i ++ ) Console . Write ( res [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } }
Generate a list of n consecutive composite numbers ( An interesting method ) | C # program to print n consecutive composite numbers ; function to find factorial of given number ; Prints n consecutive numbers . ; Driver program to test above function
using System ; public class Program { static long factorial ( int n ) { long res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { res *= i ; } return res ; } static void printNComposite ( int n ) { long fact = factorial ( n + 1 ) ; for ( int i = 2 ; i <= n + 1 ; ++ i ) { Console . Write ( fact + i + " ▁ " ) ; } } public static void Main ( ) { int n = 4 ; printNComposite ( n ) ; } }
Frugal Number | Program to check for Frugal number ; Finding primes upto entered number ; Finding primes by Sieve of Eratosthenes method ; If prime [ i ] is not changed , then it is prime ; Update all multiples of p ; Forming array of the prime numbers found ; Returns number of digits in n ; Checking whether a number is Frugal or not ; Finding number of digits in prime factorization of the number ; Exponent for current factor ; Counting number of times this prime factor divides ( Finding exponent ) ; Finding number of digits in the exponent Avoiding exponents of value 1 ; Checking condition for frugal number ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static List < long > primes ( long n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = i * 2 ; j <= n ; j += i ) prime [ j ] = false ; } } List < long > arr = new List < long > ( ) ; for ( int i = 2 ; i < n ; i ++ ) if ( prime [ i ] ) arr . Add ( i ) ; return arr ; } static int countDigits ( long n ) { long temp = n ; int c = 0 ; while ( temp != 0 ) { temp = temp / 10 ; c ++ ; } return c ; } static bool frugal ( long n ) { List < long > r = primes ( n ) ; long t = n ; long s = 0 ; for ( int i = 0 ; i < r . Count ; i ++ ) { if ( t % r [ i ] == 0 ) { long k = 0 ; while ( t % r [ i ] == 0 ) { t = t / r [ i ] ; k ++ ; } if ( k == 1 ) s = s + countDigits ( r [ i ] ) ; else if ( k != 1 ) s = s + countDigits ( r [ i ] ) + countDigits ( k ) ; } } return ( countDigits ( n ) > s && s != 0 ) ; } static void Main ( ) { long n = 343 ; if ( frugal ( n ) ) Console . Write ( " A ▁ Frugal ▁ number STRNEWLINE " ) ; else Console . Write ( " Not ▁ a ▁ frugal ▁ number STRNEWLINE " ) ; } }
N | C # program to find n - th number which is both square and cube . ; Driver code
using System ; class GFG { static int nthSquareCube ( int n ) { return n * n * n * n * n * n ; } static public void Main ( ) { int n = 5 ; Console . WriteLine ( nthSquareCube ( n ) ) ; } }
Squared triangular number ( Sum of cubes ) | C # program to check if a given number is sum of cubes of natural numbers . ; Function to find if the given number is sum of the cubes of first n natural numbers ; Start adding cubes of the numbers from 1 ; If sum becomes equal to s return n ; Driver code
using System ; class GFG { public static int findS ( int s ) { int sum = 0 ; for ( int n = 1 ; sum < s ; n ++ ) { sum += n * n * n ; if ( sum == s ) return n ; } return - 1 ; } static public void Main ( string [ ] args ) { int s = 9 ; int n = findS ( s ) ; if ( n == - 1 ) Console . WriteLine ( " - 1" ) ; else Console . WriteLine ( n ) ; } }
Number with even sum of digits | C # program to find n - th Good number . ; Function to find kth good number ; Find the last digit of n . ; If last digit is between 0 to 4 then return 2 * n . ; If last digit is between 5 to 9 then return 2 * n + 1. ; Driver code
using System ; class GFG { public static int findKthGoodNo ( int n ) { int lastDig = n % 10 ; if ( lastDig >= 0 && lastDig <= 4 ) return n << 1 ; else return ( n << 1 ) + 1 ; } static public void Main ( string [ ] args ) { int n = 10 ; Console . WriteLine ( findKthGoodNo ( n ) ) ; } }
Nicomachu 's Theorem | C # program to verify Nicomachu 's Theorem ; Compute sum of cubes ; Check if sum is equal to given formula . ; Driver Code
using System ; class GFG { static void NicomachuTheorum_sum ( int n ) { int sum = 0 ; for ( int k = 1 ; k <= n ; k ++ ) sum += k * k * k ; int triNo = n * ( n + 1 ) / 2 ; if ( sum == triNo * triNo ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( ) { int n = 5 ; NicomachuTheorum_sum ( n ) ; } }
Largest even digit number not greater than N | C # program to print the largest integer not greater than N with all even digits ; function to check if all digits are even of a given number ; iterate for all digits ; if digit is odd ; all digits are even ; function to return the largest number with all digits even ; iterate till we find a number with all digits even ; Driver Code
using System ; public class GFG { static int checkDigits ( int n ) { while ( n > 0 ) { if ( ( ( n % 10 ) % 2 ) > 0 ) return 0 ; n /= 10 ; } return 1 ; } static int largestNumber ( int n ) { for ( int i = n ; ; i -- ) if ( checkDigits ( i ) > 0 ) return i ; } static public void Main ( ) { int N = 23 ; Console . WriteLine ( largestNumber ( N ) ) ; } }
Largest even digit number not greater than N | C # program to print the largest integer not greater than N with all even digits ; function to return the largest number with all digits even ; convert the number to a string for easy operations ; find first odd digit ; if no digit , then N is the answer ; till first odd digit , add all even numbers ; decrease 1 from the odd digit ; add 0 in the rest of the digits ; Driver Code
using System ; class GFG { static int largestNumber ( int n ) { string s = " " ; int duplicate = n ; while ( n > 0 ) { s = ( char ) ( n % 10 + 48 ) + s ; n /= 10 ; } int index = - 1 ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( ( ( ( int ) ( s [ i ] - '0' ) % 2 ) & 1 ) > 0 ) { index = i ; break ; } } if ( index == - 1 ) return duplicate ; int num = 0 ; for ( int i = 0 ; i < index ; i ++ ) num = num * 10 + ( int ) ( s [ i ] - '0' ) ; num = num * 10 + ( ( int ) s [ index ] - ( int ) ( '0' ) - 1 ) ; for ( int i = index + 1 ; i < s . Length ; i ++ ) num = num * 10 + 8 ; return num ; } static void Main ( ) { int N = 24578 ; Console . WriteLine ( largestNumber ( N ) ) ; } }
Number of digits in 2 raised to power n | C # program to find number of digits in 2 ^ n ; Function to find number of digits in 2 ^ n ; Driver code
using System ; class GFG { static int countDigits ( int n ) { return ( int ) ( n * Math . Log10 ( 2 ) + 1 ) ; } static void Main ( ) { int n = 5 ; Console . Write ( countDigits ( n ) ) ; } }
Smallest even digits number not less than N | C # program to print the smallest integer not less than N with all even digits ; function to check if all digits are even of a given number ; iterate for all digits ; if digit is odd ; all digits are even ; function to return the smallest number with all digits even ; iterate till we find a number with all digits even ; Driver Code
using System ; class GFG { static int check_digits ( int n ) { while ( n != 0 ) { if ( ( n % 10 ) % 2 != 0 ) return 0 ; n /= 10 ; } return 1 ; } static int smallest_number ( int n ) { for ( int i = n ; ; i ++ ) if ( check_digits ( i ) != 0 ) return i ; } public static void Main ( ) { int N = 2397 ; Console . WriteLine ( smallest_number ( N ) ) ; } }
Smallest triangular number larger than p | C # code to find the bucket to choose for picking flowers out of it ; Driver code
using System ; class GFG { static int findBucketNo ( int p ) { return ( int ) Math . Ceiling ( ( Math . Sqrt ( 8 * p + 1 ) - 1 ) / 2 ) ; } static public void Main ( ) { int p = 10 ; Console . WriteLine ( findBucketNo ( p ) ) ; } }
LCM of factorial and its neighbors | Program to calculate the LCM of N ! and its neighbor ( N - 1 ) ! and ( N + 1 ) ! ; function to calculate the factorial ; returning the factorial of the largest number in the given three consecutive numbers ; Driver code
using System ; class GFG { static int factorial ( int n ) { if ( n == 0 ) return 1 ; return n * factorial ( n - 1 ) ; } static int LCMOfNeighbourFact ( int n ) { return factorial ( n + 1 ) ; } public static void Main ( ) { int N = 5 ; Console . WriteLine ( LCMOfNeighbourFact ( N ) ) ; } }
Expressing factorial n as sum of consecutive numbers | C # program to count number of ways we can express a factorial as sum of consecutive numbers ; sieve of Eratosthenes to compute the prime numbers ; Store all prime numbers ; function to calculate the largest power of a prime in a number ; Modular multiplication to avoid the overflow of multiplication Please see below for details https : www . geeksforgeeks . org / how - to - avoid - overflow - in - modular - multiplication / ; Returns count of ways to express n ! as sum of consecutives . ; We skip 2 ( First prime ) as we need to consider only odd primes ; compute the largest power of prime ; if the power of current prime number is zero in N ! , power of primes greater than current prime number will also be zero , so break out from the loop ; multiply the result at every step ; subtract 1 to exclude the case of 1 being an odd divisor ; Driver function
using System ; using System . Collections ; class GFG { static int MAX = 50002 ; static ArrayList primes = new ArrayList ( ) ; public static void sieve ( ) { bool [ ] isPrime = new bool [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) isPrime [ i ] = true ; for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( isPrime [ p ] == true ) { for ( int i = p * 2 ; i < MAX ; i += p ) isPrime [ i ] = false ; } } for ( int p = 2 ; p < MAX ; p ++ ) if ( isPrime [ p ] == true ) primes . Add ( p ) ; } public static int power_prime ( int x , int y ) { int count = 0 ; int z = y ; while ( x >= z ) { count += ( x / z ) ; z *= y ; } return count ; } public static int modMult ( int a , int b , int mod ) { int res = 0 ; a = a % mod ; while ( b > 0 ) { if ( b % 2 == 1 ) res = ( res + a ) % mod ; a = ( a * 2 ) % mod ; b /= 2 ; } return res % mod ; } public static int countWays ( int n , int m ) { int ans = 1 ; for ( int i = 1 ; i < primes . Count ; i ++ ) { int powers = power_prime ( n , Convert . ToInt32 ( primes [ i ] ) ) ; if ( powers == 0 ) break ; ans = modMult ( ans , powers + 1 , m ) % m ; } if ( ( ( ans - 1 ) % m ) < 0 ) return ( ans - 1 + m ) % m ; else return ( ans - 1 ) % m ; } public static void Main ( ) { sieve ( ) ; int n = 4 , m = 7 ; Console . WriteLine ( countWays ( n , m ) ) ; } }
Check if the given two numbers are friendly pair or not | C # code to check if the given two number are friendly pair or not ; Returns sum of all factors of n . ; Traversing through all prime factors . ; THE BELOW STATEMENT MAKES IT BETTER THAN ABOVE METHOD AS WE REDUCE VALUE OF n . ; This condition is to handle the case when n is a prime number greater than 2. ; Function to return gcd of a and b ; Function to check if the given two number are friendly pair or not ; Finding the sum of factors of n and m ; finding gcd of n and sum of its factors . ; finding gcd of m and sum of its factors . ; checking is numerator and denominator of abundancy index of both number are equal or not ; Driver code
using System ; class GFG { static int sumofFactors ( int n ) { int res = 1 ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { int count = 0 , curr_sum = 1 ; int curr_term = 1 ; while ( n % i == 0 ) { count ++ ; n = n / i ; curr_term *= i ; curr_sum += curr_term ; } res *= curr_sum ; } if ( n >= 2 ) res *= ( 1 + n ) ; return res ; } static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static bool checkFriendly ( int n , int m ) { int sumFactors_n = sumofFactors ( n ) ; int sumFactors_m = sumofFactors ( m ) ; int gcd_n = gcd ( n , sumFactors_n ) ; int gcd_m = gcd ( m , sumFactors_m ) ; if ( n / gcd_n == m / gcd_m && sumFactors_n / gcd_n == sumFactors_m / gcd_m ) return true ; else return false ; } public static void Main ( String [ ] args ) { int n = 6 , m = 28 ; if ( checkFriendly ( n , m ) ) Console . Write ( " Yes STRNEWLINE " ) ; else Console . Write ( " No STRNEWLINE " ) ; } }
Find n | C # program to find n - th Fortunate number ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to Find primorial of order n ( product of first n prime numbers ) . ; Function to find next prime number greater than n ; Note that difference ( or m ) should be greater than 1. ; loop continuously until isPrime returns true for a number above n ; Ignoring the prime number that is 1 greater than n ; Returns n - th Fortunate number ; Driver Code
using System ; class GFG { public 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 ; } public static int primorial ( int n ) { int p = 2 ; n -- ; for ( int i = 3 ; n != 0 ; i ++ ) { if ( isPrime ( i ) == true ) { p = p * i ; n -- ; } i ++ ; } return p ; } public static int findNextPrime ( int n ) { int nextPrime = n + 2 ; while ( true ) { if ( isPrime ( nextPrime ) == true ) break ; nextPrime ++ ; } return nextPrime ; } public static int fortunateNumber ( int n ) { int p = primorial ( n ) ; return findNextPrime ( p ) - p ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( fortunateNumber ( n ) ) ; } }
Probability for three randomly chosen numbers to be in AP | C # program to find probability that 3 randomly chosen numbers form AP . ; function to calculate probability ; Driver code
using System ; class GFG { static double procal ( int n ) { return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ; } public static void Main ( ) { int [ ] a = { 1 , 2 , 3 , 4 , 5 } ; int n = a . Length ; Console . Write ( Math . Round ( procal ( n ) * 1000000.0 ) / 1000000.0 ) ; } }
Fermat 's Last Theorem | C # program to verify fermat 's last theorem for a given range and n. ; Check if there exists a triplet such that a ^ n + b ^ n = c ^ n ; Driver code
using System ; class GFG { static void testSomeNumbers ( int limit , int n ) { if ( n < 3 ) return ; for ( int a = 1 ; a <= limit ; a ++ ) for ( int b = a ; b <= limit ; b ++ ) { int pow_sum = ( int ) ( Math . Pow ( a , n ) + Math . Pow ( b , n ) ) ; double c = Math . Pow ( pow_sum , 1.0 / n ) ; int c_pow = ( int ) Math . Pow ( ( int ) c , n ) ; if ( c_pow == pow_sum ) { Console . WriteLine ( " Count ▁ example ▁ found " ) ; return ; } } Console . WriteLine ( " No ▁ counter ▁ example ▁ within " + " ▁ given ▁ range ▁ and ▁ data " ) ; } public static void Main ( ) { testSomeNumbers ( 12 , 3 ) ; } }
Product of given N fractions in reduced form | C # program to find product of N fractions in reduced form . ; Function to return gcd of a and b ; Print the Product of N fraction in Reduced Form . ; finding the product of all N numerators and denominators . ; Finding GCD of new numerator and denominator ; Converting into reduced form . ; Driven Program
using System ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static void productReduce ( int n , int [ ] num , int [ ] den ) { int new_num = 1 , new_den = 1 ; for ( int i = 0 ; i < n ; i ++ ) { new_num *= num [ i ] ; new_den *= den [ i ] ; } int GCD = gcd ( new_num , new_den ) ; new_num /= GCD ; new_den /= GCD ; Console . WriteLine ( new_num + " / " + new_den ) ; } public static void Main ( ) { int n = 3 ; int [ ] num = { 1 , 2 , 5 } ; int [ ] den = { 2 , 1 , 6 } ; productReduce ( n , num , den ) ; } }
Find value of ( n ^ 1 + n ^ 2 + n ^ 3 + n ^ 4 ) mod 5 for given n | Code for finding the value of f ( n ) mod 5 for given n . ; function for f ( n ) mod 5 ; if n % 5 == 1 return 4 ; else return 0 ; Driver program
using System ; class GFG { static int fnMod ( int n ) { if ( n % 5 == 1 ) return 4 ; else return 0 ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( fnMod ( n ) ) ; n = 11 ; Console . WriteLine ( fnMod ( n ) ) ; } }
Recursive sum of digits of a number formed by repeated appends | C # program to find Sum of digits of a number formed by repeating a number X number of times until sum becomes single digit . ; return single digit sum of a number . ; Returns recursive sum of digits of a number formed by repeating a number X number of times until sum become single digit . ; driver program
using System ; public class GFG { static int digSum ( int n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } static int repeatedNumberSum ( int n , int x ) { int sum = x * digSum ( n ) ; return digSum ( sum ) ; } public static void Main ( ) { int n = 24 , x = 3 ; Console . Write ( repeatedNumberSum ( n , x ) ) ; } }
Sum of n digit numbers divisible by a given number | Simple C # program to sum of n digit divisible numbers . ; Returns sum of n digit numbers divisible by ' number ' ; compute the first and last term ; sum of number which having n digit and divisible by number ; Driver code
using System ; class GFG { static int totalSumDivisibleByNum ( int n , int number ) { int firstnum = ( int ) Math . Pow ( 10 , n - 1 ) ; int lastnum = ( int ) Math . Pow ( 10 , n ) ; int sum = 0 ; for ( int i = firstnum ; i < lastnum ; i ++ ) if ( i % number == 0 ) sum += i ; return sum ; } public static void Main ( ) { int n = 3 , num = 7 ; Console . WriteLine ( totalSumDivisibleByNum ( n , num ) ) ; } }
Extended Midy 's theorem | C # program to demonstrate extended Midy 's theorem ; Returns repeating sequence of a fraction . If repeating sequence doesn 't exits, then returns -1 ; Create a map to store already seen remainders remainder is used as key and its position in result is stored as value . Note that we need position for cases like 1 / 6. In this case , the recurring sequence doesn 't start from first  remainder.  ; Find first remainder ; Keep finding remainder until either remainder becomes 0 or repeats ; Store this remainder ; Multiply remainder with 10 ; Append rem / denr to result ; Update remainder ; Checks whether a number is prime or not ; If all conditions are met , it proves Extended Midy 's theorem ; Dividing repeated part into m parts ; Computing sum of parts . ; Checking for Extended Midy ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static string fractionToDecimal ( int numerator , int denominator ) { string res = " " ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; int rem = numerator % denominator ; while ( ( rem != 0 ) && ! mp . ContainsKey ( rem ) ) { mp [ rem ] = res . Length ; rem = rem * 10 ; int res_part = rem / denominator ; res += res_part + " " ; rem = rem % denominator ; } return ( rem == 0 ) ? " - 1" : res . Substring ( mp [ rem ] ) ; } static bool isPrime ( int n ) { for ( int i = 2 ; i <= n / 2 ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static void ExtendedMidys ( string str , int n , int m ) { if ( ! isPrime ( n ) ) { Console . Write ( " Denominator ▁ is ▁ not ▁ prime , ▁ " + " thus ▁ Extended ▁ Midy ' s ▁ theorem ▁ " + " is ▁ not ▁ applicable " ) ; return ; } int l = str . Length ; if ( l % 2 == 0 && l % m == 0 ) { int [ ] part = new int [ m ] ; int sum = 0 , res = 0 ; for ( int i = 0 ; i < l ; i ++ ) { int var = i / m ; part [ var ] = part [ var ] * 10 + ( str [ i ] - '0' ) ; } for ( int i = 0 ; i < m ; i ++ ) { sum = sum + part [ i ] ; Console . Write ( part [ i ] + " ▁ " ) ; } Console . WriteLine ( ) ; res = ( int ) Math . Pow ( 10 , m ) - 1 ; if ( sum % res == 0 ) Console . Write ( " Extended ▁ Midy ' s ▁ " + " theorem ▁ holds ! " ) ; else Console . Write ( " Extended ▁ Midy ' s ▁ " + " theorem ▁ doesn ' t ▁ hold ! " ) ; } else if ( l % 2 != 0 ) { Console . Write ( " The ▁ repeating ▁ decimal ▁ is ▁ of ▁ " + " odd ▁ length ▁ thus ▁ Extended ▁ Midy ' s ▁ " + " theorem ▁ is ▁ not ▁ applicable " ) ; } else if ( l % m != 0 ) { Console . Write ( " The ▁ repeating ▁ decimal ▁ can ▁ " + " not ▁ be ▁ divided ▁ into ▁ m ▁ digits " ) ; } } public static void Main ( string [ ] args ) { int numr = 1 , denr = 17 , m = 4 ; string res = fractionToDecimal ( numr , denr ) ; if ( res == " - 1" ) Console . Write ( " The ▁ fraction ▁ does ▁ not ▁ " + " have ▁ repeating ▁ decimal " ) ; else { Console . WriteLine ( " Repeating ▁ decimal ▁ = ▁ " + res ) ; ExtendedMidys ( res , denr , m ) ; } } }
Count n digit numbers divisible by given number | Simple C # program to count n digit divisible numbers . ; Returns count of n digit numbers divisible by ' number ' ; compute the first and last term ; count total number of which having n digit and divisible by number ; Driver code
using System ; class GFG { static int numberofterm ( int n , int number ) { int firstnum = ( int ) Math . Pow ( 10 , n - 1 ) ; int lastnum = ( int ) Math . Pow ( 10 , n ) ; int count = 0 ; for ( int i = firstnum ; i < lastnum ; i ++ ) if ( i % number == 0 ) count ++ ; return count ; } public static void Main ( ) { int n = 3 , num = 7 ; Console . Write ( numberofterm ( n , num ) ) ; } }