codeparrot/xlcost-text-to-code huggingface dataset:
Given two numbers a and b find all x such that a % x = b | C # program to find x such that a % x is equal to b . ; if a is less than b then no solution ; if a is equal to b then every number greater than a will be the solution so its infinity ; count variable store the number of values possible ; checking for both divisor and quotient whether they divide ( a - b ) completely and greater than b . ; Here y is added twice in the last iteration so 1 y should be decremented to get correct solution ; Driver code
using System ; class GFG { static void modularEquation ( int a , int b ) { if ( a < b ) { Console . WriteLine ( " No ▁ solution ▁ possible ▁ " ) ; return ; } if ( a == b ) { Console . WriteLine ( " Infinite ▁ Solution ▁ possible ▁ " ) ; return ; } int count = 0 ; int n = a - b ; int y = ( int ) Math . Sqrt ( a - b ) ; for ( int i = 1 ; i <= y ; ++ i ) { if ( n % i == 0 ) { if ( n / i > b ) count ++ ; if ( i > b ) count ++ ; } } if ( y * y == n && y > b ) count -- ; Console . WriteLine ( count ) ; } public static void Main ( ) { int a = 21 , b = 5 ; modularEquation ( a , b ) ; } }
Count different numbers that can be generated such that there digits sum is equal to ' n ' | C # program to count ways to write ' n ' as sum of digits ; Function to count ' num ' as sum of digits ( 1 , 2 , 3 , 4 ) ; Initialize dp [ ] array ; Base case ; Initialize the current dp [ ] array as '0' ; if i == j then there is only one way to write with element itself ' i ' ; If j == 1 , then there exist two ways , one from '1' and other from '4' ; if i - j is positive then pick the element from ' i - j ' element of dp [ ] array ; Check for modulas ; return the final answer ; Driver code
using System ; public class GFG { static int countWays ( int num ) { int [ ] dp = new int [ num + 1 ] ; int MOD = ( int ) 1E9 + 7 ; dp [ 1 ] = 2 ; for ( int i = 2 ; i <= num ; ++ i ) { dp [ i ] = 0 ; for ( int j = 1 ; j <= 3 ; ++ j ) { if ( i - j == 0 ) dp [ i ] += 1 ; else if ( j == 1 ) dp [ i ] += dp [ i - j ] * 2 ; else if ( i - j > 0 ) dp [ i ] += dp [ i - j ] ; if ( dp [ i ] >= MOD ) dp [ i ] %= MOD ; } } return dp [ num ] ; } static public void Main ( String [ ] args ) { int n = 3 ; Console . WriteLine ( countWays ( n ) ) ; } }
Check whether a number can be represented by sum of two squares | An efficient approach based implementation to find if a number can be written as sum of two squares . ; function to check if there exist two numbers sum of whose squares is n . ; store square value in hashmap ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static bool sumSquare ( int n ) { Dictionary < int , int > s = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i * i <= n ; ++ i ) { s . Add ( i * i , 1 ) ; if ( s . ContainsKey ( n - i * i ) ) { Console . WriteLine ( ( int ) Math . Sqrt ( n - i * i ) + " ^ 2 ▁ + ▁ " + i + " ^ 2" ) ; return true ; } } return false ; } public static void Main ( String [ ] args ) { int n = 169 ; Console . WriteLine ( sumSquare ( n ) ? " YES " : " NO " ) ; } }
Check whether a number can be represented by sum of two squares | C # program to Check whether a number can be represented by sum of two squares using Fermat Theorem . ; Count all the prime factors . ; If any prime factor of the form ( 4 k + 3 ) ( 4 k + 3 ) occurs an odd number of times . ; If n itself is a prime number and can be expressed in the form of 4 k + 3 we return false . ; Driver Code
using System ; class GFG { public static bool judgeSquareSum ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { int count = 0 ; if ( n % i == 0 ) { while ( n % i == 0 ) { count ++ ; n /= i ; } if ( i % 4 == 3 && count % 2 != 0 ) return false ; } } return n % 4 != 3 ; } static public void Main ( ) { int n = 17 ; if ( judgeSquareSum ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Total no of 1 's in numbers | C # code to count the frequency of 1 in numbers less than or equal to the given number . ; function to count the frequency of 1. ; Driver Code
using System ; class GFG { static int countDigitOne ( int n ) { int countr = 0 ; for ( int i = 1 ; i <= n ; i *= 10 ) { int divider = i * 10 ; countr += ( n / divider ) * i + Math . Min ( Math . Max ( n % divider - i + 1 , 0 ) , i ) ; } return countr ; } public static void Main ( ) { int n = 13 ; Console . WriteLine ( countDigitOne ( n ) ) ; n = 113 ; Console . WriteLine ( countDigitOne ( n ) ) ; n = 205 ; Console . WriteLine ( countDigitOne ( n ) ) ; } }
Divisors of n | C # program to count number of divisors of n ^ 2 which are not divisible by divisor of n ; Function to count divisors of n ^ 2 having no factors of ' n ' ; Increment count of i - th prime divisor ; Find next prime divisor ; Increment count if divisor still remains ; Initialize variable for counting the factors of n ^ 2 and n as ans1 and ans2 respectively ; Range based for - loop ; Use formula as discussed in above ; return the difference of answers ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int factors ( int n ) { Dictionary < int , int > prime = new Dictionary < int , int > ( ) ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; ++ i ) { while ( n % i == 0 ) { if ( prime . ContainsKey ( i ) ) { prime [ i ] = prime [ i ] + 1 ; } else { prime . Add ( i , 1 ) ; } n = n / i ; } } if ( n > 2 ) { if ( prime . ContainsKey ( n ) ) { prime [ n ] = prime [ n ] + 1 ; } else { prime . Add ( n , 1 ) ; } } int ans1 = 1 , ans2 = 1 ; foreach ( KeyValuePair < int , int > it in prime ) { ans1 *= 2 * it . Value + 1 ; ans2 *= it . Value + 1 ; } return ans1 - ans2 ; } public static void Main ( String [ ] args ) { int n = 5 ; Console . WriteLine ( factors ( n ) ) ; n = 8 ; Console . WriteLine ( factors ( n ) ) ; } }
Print digit 's position to be removed to make a number divisible by 6 | C # program to print digit 's position to be removed to make number divisible by 6 ; function to print the number divisible by 6 after exactly removing a digit ; stores the sum of all elements ; traverses the string and converts string to number array and sums up ; if ( a [ n - 1 ] % 2 != 0 ) ODD CHECK ; if second last is odd or sum of n - 1 elements are not divisible by 3. ; second last is even and print n - 1 elements removing last digit ; last digit removed ; counter to check if any element after removing , its sum % 3 == 0 ; traverse till second last element ; to check if any element after removing , its sum % 3 == 0 ; the leftmost element ; break at the leftmost element ; stores the right most element ; if no element has been found as a [ i + 1 ] > a [ i ] ; if second last is even , then remove last if ( sum - last ) % 3 == 0 ; if no element which on removing gives sum % 3 == 0 ; Driver Code
using System ; class GFG { static void greatest ( string s ) { int n = s . Length ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = s [ i ] - '0' ; sum += a [ i ] ; } { if ( a [ n - 2 ] % 2 != 0 || ( sum - a [ n - 1 ] ) % 3 != 0 ) { Console . Write ( " - 1" ) ; } else { Console . Write ( n ) ; } } else { int re = sum % 3 ; int del = - 1 ; int flag = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( ( a [ i ] ) % 3 == re ) { if ( a [ i + 1 ] > a [ i ] ) { del = i ; flag = 1 ; break ; } else { del = i ; } } } if ( flag == 0 ) { if ( a [ n - 2 ] % 2 == 0 && re == a [ n - 1 ] % 3 ) del = n - 1 ; } if ( del == - 1 ) Console . Write ( - 1 ) ; else { Console . Write ( del + 1 ) ; } } } public static void Main ( ) { string s = "7510222" ; greatest ( s ) ; } }
Representation of a number in powers of other | C # program to check if m can be represented as powers of w . ; break ; None of 3 worked . ; If m is not zero means , it can 't be represented  in terms of powers of w. ; Driver Code
using System ; class GFG { static bool asPowerSum ( int w , int m ) { while ( m > 0 ) { if ( ( m - 1 ) % w == 0 ) m = ( m - 1 ) / w ; else if ( ( m + 1 ) % w == 0 ) m = ( m + 1 ) / w ; else if ( m % w == 0 ) m = m / w ; else } return ( m == 0 ) ; } static public void Main ( ) { int w = 3 , m = 7 ; if ( asPowerSum ( w , m ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Number of digits to be removed to make a number divisible by 3 | C # program to find the minimum number of digits to be removed to make a large number divisible by 3. ; function to count the no of removal of digits to make a very large number divisible by 3 ; add up all the digits of num ; if num is already is divisible by 3 then no digits are to be removed ; if there is single digit , then it is not possible to remove one digit . ; traverse through the number and find out if any number on removal makes the sum divisible by 3 ; if there are two numbers then it is not possible to remove two digits . ; Otherwise we can always make a number multiple of 2 by removing 2 digits . ; Driver Code
using System ; class GFG { static int divisible ( String num ) { int n = num . Length ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( int ) ( num [ i ] ) ; if ( sum % 3 == 0 ) return 0 ; if ( n == 1 ) return - 1 ; for ( int i = 0 ; i < n ; i ++ ) if ( sum % 3 == ( num [ i ] - '0' ) % 3 ) return 1 ; if ( n == 2 ) return - 1 ; return 2 ; } public static void Main ( ) { string num = "1234" ; Console . WriteLine ( divisible ( num ) ) ; } }
Program for dot product and cross product of two vectors | C # implementation for dot product and cross product of two vector . ; Function that return dot product of two vector array . ; Loop for calculate cot product ; Function to find cross product of two vector array . ; Driver code ; dotProduct function call ; crossProduct function call ; Loop that print cross product of two vector array .
using System ; class GFG { static int n = 3 ; static int dotProduct ( int [ ] vect_A , int [ ] vect_B ) { int product = 0 ; for ( int i = 0 ; i < n ; i ++ ) product = product + vect_A [ i ] * vect_B [ i ] ; return product ; } static void crossProduct ( int [ ] vect_A , int [ ] vect_B , int [ ] cross_P ) { cross_P [ 0 ] = vect_A [ 1 ] * vect_B [ 2 ] - vect_A [ 2 ] * vect_B [ 1 ] ; cross_P [ 1 ] = vect_A [ 2 ] * vect_B [ 0 ] - vect_A [ 0 ] * vect_B [ 2 ] ; cross_P [ 2 ] = vect_A [ 0 ] * vect_B [ 1 ] - vect_A [ 1 ] * vect_B [ 0 ] ; } public static void Main ( ) { int [ ] vect_A = { 3 , - 5 , 4 } ; int [ ] vect_B = { 2 , 6 , 5 } ; int [ ] cross_P = new int [ n ] ; Console . Write ( " Dot ▁ product : " ) ; Console . WriteLine ( dotProduct ( vect_A , vect_B ) ) ; Console . Write ( " Cross ▁ product : " ) ; crossProduct ( vect_A , vect_B , cross_P ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( cross_P [ i ] + " ▁ " ) ; } }
Number of n digit numbers that do not contain 9 | C # program to find number of n digit numbers that do not contain 9 as it 's digit ; function to find number of n digit numbers possible ; Driver Code
using System ; public class GFG { static int totalNumber ( int n ) { return 8 * ( int ) Math . Pow ( 9 , n - 1 ) ; } static public void Main ( ) { int n = 3 ; Console . WriteLine ( totalNumber ( n ) ) ; } }
Count ways to express even number â €˜ nâ €™ as sum of even integers | C # program to count ways to write number as sum of even integers ; Initialize mod variable as constant ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Return number of ways to write ' n ' as sum of even integers ; Driver code
using System ; class GFG { static int MOD = 1000000007 ; static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( 1 * res * x ) % p ; x = ( 1 * x * x ) % p ; } return res ; } static int countEvenWays ( int n ) { return power ( 2 , n / 2 - 1 , MOD ) ; } public static void Main ( ) { int n = 6 ; Console . WriteLine ( countEvenWays ( n ) ) ; n = 8 ; Console . WriteLine ( countEvenWays ( n ) ) ; } }
Number of steps to convert to prime factors | C # program to count number of steps required to convert an integer array to array of factors . ; array to store prime factors ; function to generate all prime factors of numbers from 1 to 10 ^ 6 ; Initializes all the positions with their value . ; Initializes all multiples of 2 with 2 ; A modified version of Sieve of Eratosthenes to store the smallest prime factor that divides every number . ; check if it has no prime factor . ; Initializes of j starting from i * i ; if it has no prime factor before , then stores the smallest prime divisor ; function to calculate the number of representations ; keep an count of prime factors ; traverse for every element ; count the no of factors ; subtract 1 if Ai is not 1 as the last step wont be taken into count ; Driver code ; call sieve to calculate the factors
using System ; class GFG { static int MAX = 1000001 ; static int [ ] factor = new int [ MAX ] ; static void cal_factor ( ) { factor [ 1 ] = 1 ; for ( int i = 2 ; i < MAX ; i ++ ) factor [ i ] = i ; for ( int i = 4 ; i < MAX ; i += 2 ) factor [ i ] = 2 ; for ( int i = 3 ; i * i < MAX ; i ++ ) { if ( factor [ i ] == i ) { for ( int j = i * i ; j < MAX ; j += i ) { if ( factor [ j ] == j ) factor [ j ] = i ; } } } } static int no_of_representations ( int [ ] a , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int temp = a [ i ] ; int flag = 0 ; while ( factor [ temp ] != 1 ) { flag = - 1 ; count ++ ; temp = temp / factor [ temp ] ; } count += flag ; } return count ; } public static void Main ( ) { cal_factor ( ) ; int [ ] a = { 4 , 4 , 4 } ; int n = a . Length ; Console . WriteLine ( no_of_representations ( a , n ) ) ; } }
Subsequences of size three in an array whose sum is divisible by m | C # program to find count of subsequences of size three divisible by M . ; Three nested loop to find all the sub sequences of length three in the given array A [ ] . ; checking if the sum of the chosen three number is divisible by m . ; Driver code
using System ; class GFG { static int coutSubSeq ( int [ ] A , int N , int M ) { int sum = 0 ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = j + 1 ; k < N ; k ++ ) { sum = A [ i ] + A [ j ] + A [ k ] ; if ( sum % M == 0 ) ans ++ ; } } } return ans ; } public static void Main ( ) { int M = 3 ; int [ ] A = { 1 , 2 , 4 , 3 } ; int N = A . Length ; Console . WriteLine ( coutSubSeq ( A , N , M ) ) ; } }
Subsequences of size three in an array whose sum is divisible by m | C # program to find count of subsequences of size three divisible by M . ; Storing frequencies of all remainders when divided by M . ; including i and j in the sum rem calculate the remainder required to make the sum divisible by M ; if the required number is less than j , we skip as we have already calculated for that value before . As j here starts with i and rem is less than j . ; if satisfies the first case . ; if satisfies the second case ; if satisfies the third case ; Driver code
using System ; class GFG { static int countSubSeq ( int [ ] A , int N , int M ) { int ans = 0 ; int [ ] h = new int [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = A [ i ] % M ; h [ A [ i ] ] ++ ; } for ( int i = 0 ; i < M ; i ++ ) { for ( int j = i ; j < M ; j ++ ) { int rem = ( M - ( i + j ) % M ) % M ; if ( rem < j ) continue ; if ( i == j && rem == j ) ans += h [ i ] * ( h [ i ] - 1 ) * ( h [ i ] - 2 ) / 6 ; else if ( i == j ) ans += h [ i ] * ( h [ i ] - 1 ) * h [ rem ] / 2 ; else if ( i == rem ) ans += h [ i ] * ( h [ i ] - 1 ) * h [ j ] / 2 ; else if ( rem == j ) ans += h [ j ] * ( h [ j ] - 1 ) * h [ i ] / 2 ; else ans = ans + h [ i ] * h [ j ] * h [ rem ] ; } } return ans ; } public static void Main ( ) { int M = 3 ; int [ ] A = { 1 , 2 , 4 , 3 } ; int N = A . Length ; Console . WriteLine ( countSubSeq ( A , N , M ) ) ; } }
Find n | C # program to find nth term ; utility function ; since first element of the series is 7 , we initialise a variable with 7 ; Using iteration to find nth term ; Driver code
using System ; class GFG { static int findTerm ( int n ) { if ( n == 1 ) return n ; else { int term = 7 ; for ( int i = 2 ; i <= n ; i ++ ) term = term * 2 + ( i - 1 ) ; return term ; } } public static void Main ( ) { int n = 5 ; Console . WriteLine ( findTerm ( n ) ) ; } }
Find n | C # program to find the value at n - th place in the given sequence ; Returns n - th number in sequence 1 , 1 , 2 , 1 , 2 , 3 , 1 , 2 , 4 , ... ; One by one subtract counts elements in different blocks ; Driver code
using System ; class GFG { static int findNumber ( int n ) { n -- ; int i = 1 ; while ( n >= 0 ) { n -= i ; ++ i ; } return ( n + i ) ; } public static void Main ( ) { int n = 3 ; Console . WriteLine ( findNumber ( n ) ) ; } }
Program to find correlation coefficient | C # Program to find correlation coefficient ; function that returns correlation coefficient . ; sum of elements of array X . ; sum of elements of array Y . ; sum of X [ i ] * Y [ i ] . ; sum of square of array elements . ; use formula for calculating correlation coefficient . ; Driver function ; Find the size of array . ; Function call to correlationCoefficient .
using System ; class GFG { static float correlationCoefficient ( int [ ] X , int [ ] Y , int n ) { int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ; int squareSum_X = 0 , squareSum_Y = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum_X = sum_X + X [ i ] ; sum_Y = sum_Y + Y [ i ] ; sum_XY = sum_XY + X [ i ] * Y [ i ] ; squareSum_X = squareSum_X + X [ i ] * X [ i ] ; squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ; } float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / ( float ) ( Math . Sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ) ; return corr ; } public static void Main ( ) { int [ ] X = { 15 , 18 , 21 , 24 , 27 } ; int [ ] Y = { 25 , 25 , 27 , 31 , 32 } ; int n = X . Length ; Console . Write ( Math . Round ( correlationCoefficient ( X , Y , n ) * 1000000.0 ) / 1000000.0 ) ; } }
Find the number of spectators standing in the stadium at time t | C # program to find number of spectators standing at a time ; If the time is less than k then we can print directly t time . ; If the time is n then k spectators are standing . ; Otherwise we calculate the spectators standing . ; Driver code ; Stores the value of n , k and t t is time n & k is the number of specators
using System ; class GFG { static void result ( long n , long k , long t ) { if ( t <= k ) Console . WriteLine ( t ) ; else if ( t <= n ) Console . WriteLine ( k ) ; else { long temp = t - n ; temp = k - temp ; Console . WriteLine ( temp ) ; } } public static void Main ( ) { long n , k , t ; n = 10 ; k = 5 ; t = 12 ; result ( n , k , t ) ; } }
Program for weighted mean of natural numbers . | C # Program to find weighted mean of natural numbers . ; Function to calculate weighted mean . ; Driver program to test the function . ; Take num array and corresponding weight array and initialize it . ; Calculate the size of array . ; Check the size of both array is equal or not .
using System ; class GFG { static float weightedMean ( int [ ] X , int [ ] W , int n ) { int sum = 0 , numWeight = 0 ; for ( int i = 0 ; i < n ; i ++ ) { numWeight = numWeight + X [ i ] * W [ i ] ; sum = sum + W [ i ] ; } return ( float ) ( numWeight ) / sum ; } public static void Main ( ) { int [ ] X = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int [ ] W = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = X . Length ; int m = W . Length ; if ( n == m ) Console . WriteLine ( weightedMean ( X , W , n ) ) ; else Console . WriteLine ( " - 1" ) ; } }
Program to find GCD of floating point numbers | C # code for finding the GCD of two floating numbers . ; Recursive function to return gcd of a and b ; base case ; Driver Function .
using System ; class GFG { static float gcd ( double a , double b ) { if ( a < b ) return gcd ( b , a ) ; if ( Math . Abs ( b ) < 0.001 ) return ( float ) a ; else return ( float ) ( gcd ( b , a - Math . Floor ( a / b ) * b ) ) ; } public static void Main ( ) { double a = 1.20 , b = 22.5 ; Console . WriteLine ( gcd ( a , b ) ) ; } }
Program for harmonic mean of numbers | C # program to find harmonic mean of numbers . ; Function that returns harmonic mean . ; Declare sum variables and initialize with zero ; Driver code
using System ; class GFG { static float harmonicMean ( float [ ] arr , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + ( float ) 1 / arr [ i ] ; return ( float ) n / sum ; } public static void Main ( ) { float [ ] arr = { 13.5f , 14.5f , 14.8f , 15.2f , 16.1f } ; int n = arr . Length ; Console . WriteLine ( harmonicMean ( arr , n ) ) ; } }
Program for harmonic mean of numbers | C # program to find harmonic mean . ; Function that returns harmonic mean . ; Driver code
using System ; class GFG { static float harmonicMean ( int [ ] arr , int [ ] freq , int n ) { float sum = 0 , frequency_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + ( float ) freq [ i ] / arr [ i ] ; frequency_sum = frequency_sum + freq [ i ] ; } return ( frequency_sum / sum ) ; } public static void Main ( ) { int [ ] num = { 13 , 14 , 15 , 16 , 17 } ; int [ ] freq = { 2 , 5 , 13 , 7 , 3 } ; int n = num . Length ; Console . WriteLine ( harmonicMean ( num , freq , n ) ) ; } }
First collision point of two series | C # program to calculate the colliding point of two series ; Iterating through n terms of the first series ; x is i - th term of first series ; d is first element of second series and c is common difference for second series . ; If no term of first series is found ; Driver function
using System ; class GFG { static void point ( int a , int b , int c , int d , int n ) { int x , flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x = b + i * a ; if ( ( x - d ) % c == 0 && x - d >= 0 ) { Console . WriteLine ( x ) ; flag = 1 ; break ; } } if ( flag == 0 ) { Console . WriteLine ( " No ▁ collision ▁ point " ) ; } } public static void Main ( ) { int a = 20 ; int b = 2 ; int c = 9 ; int d = 19 ; int n = 20 ; point ( a , b , c , d , n ) ; } }
Armstrong Numbers between two integers | C # program to find Armstrong numbers in a range ; Prints Armstrong Numbers in given range ; number of digits calculation ; compute sum of nth power of its digits ; checks if number i is equal to the sum of nth power of its digits ; Driver code
using System ; class GFG { static void findArmstrong ( int low , int high ) { for ( int i = low + 1 ; i < high ; ++ i ) { int x = i ; int n = 0 ; while ( x != 0 ) { x /= 10 ; ++ n ; } int pow_sum = 0 ; x = i ; while ( x != 0 ) { int digit = x % 10 ; pow_sum += ( int ) Math . Pow ( digit , n ) ; x /= 10 ; } if ( pow_sum == i ) Console . Write ( i + " ▁ " ) ; } } public static void Main ( ) { int num1 = 100 ; int num2 = 400 ; findArmstrong ( num1 , num2 ) ; Console . WriteLine ( ) ; } }