codeparrot/xlcost-text-to-code huggingface dataset:
Smarandache | C # program to print the first ' n ' terms of the Smarandache - Wellin Sequence ; Function to collect first ' n ' prime numbers ; List to store first ' n ' primes ; Function to generate Smarandache - Wellin Sequence ; Storing the first ' n ' prime numbers in a list ; Driver Code
class GFG { static void primes ( int n ) { int i = 2 ; int j = 0 ; int [ ] result = new int [ n ] ; int z = 0 ; while ( j < n ) { bool flag = true ; for ( int item = 2 ; item <= ( int ) ( i * 1 / 2 ) ; item ++ ) if ( i % item == 0 && i != item ) { flag = false ; break ; } if ( flag ) { result [ z ++ ] = i ; j += 1 ; } i += 1 ; } for ( i = 0 ; i < result . Length ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) System . Console . Write ( result [ j ] ) ; System . Console . Write ( " ▁ " ) ; } } static void smar_wln ( int n ) { primes ( n ) ; } static void Main ( ) { int n = 5 ; System . Console . WriteLine ( " First ▁ " + n + " ▁ terms ▁ of ▁ the ▁ Sequence ▁ are " ) ; smar_wln ( n ) ; } }
Pentatope number | C # Program to find the nth Pentatope number ; function for Pentatope number ; formula for find Pentatope nth term ; Driver Code
using System ; class GFG { static int Pentatope_number ( int n ) { return n * ( n + 1 ) * ( n + 2 ) * ( n + 3 ) / 24 ; } public static void Main ( ) { int n = 7 ; Console . WriteLine ( n + " th ▁ " + " Pentatope ▁ number ▁ : " + Pentatope_number ( n ) ) ; n = 12 ; Console . WriteLine ( n + " th ▁ " + " Pentatope ▁ number ▁ : " + Pentatope_number ( n ) ) ; } }
Program for Centered Icosahedral Number | C # Program to find nth Centered icosahedral number Java Program to find nth Centered icosahedral number ; Function to find Centered icosahedral number ; Formula to calculate nth Centered icosahedral number and return it into main function . ; Driver Code
using System ; class GFG { static int centeredIcosahedralNum ( int n ) { return ( 2 * n + 1 ) * ( 5 * n * n + 5 * n + 3 ) / 3 ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( centeredIcosahedralNum ( n ) ) ; n = 12 ; Console . WriteLine ( centeredIcosahedralNum ( n ) ) ; } }
Centered Square Number | C # program to find nth Centered square number . ; Function to calculate Centered square number function ; Formula to calculate nth Centered square number ; Driver Code
using System ; public class GFG { static int centered_square_num ( int n ) { return n * n + ( ( n - 1 ) * ( n - 1 ) ) ; } static public void Main ( ) { int n = 7 ; Console . WriteLine ( n + " th ▁ Centered " + " ▁ square ▁ number : ▁ " + centered_square_num ( n ) ) ; } }
Sum of first n natural numbers | C # program to find sum series 1 , 3 , 6 , 10 , 15 , 21. . . and then find its sum ; Function to find the sum of series ; Driver code
using System ; class GFG { static int seriesSum ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( seriesSum ( n ) ) ; } }
Dodecagonal number | C # program to find the nth Dodecagonal number ; function for Dodecagonal number ; formula for find Dodecagonal nth term ; Driver Code
using System ; class GFG { static int Dodecagonal_number ( int n ) { return 5 * n * n - 4 * n ; } static void Main ( ) { int n = 7 ; Console . WriteLine ( Dodecagonal_number ( n ) ) ; n = 12 ; Console . WriteLine ( Dodecagonal_number ( n ) ) ; } }
Arithmetic Number | C # program to check if a number is arithmetic number or not ; Sieve Of Eratosthenes ; 1 is not a prime number ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Storing primes in an array ; Update value in primesquare [ p * p ] , if p is prime . ; Function to count divisors ; If number is 1 , then it will have only 1 as a factor . So , total factors will be 1. ; Calling SieveOfEratosthenes to store prime factors of n and to store square of prime factors of n ; ans will contain total number of distinct divisors ; Loop for counting factors of n ; a [ i ] is not less than cube root n ; Calculating power of a [ i ] in n . cnt is power of prime a [ i ] in n . ; if a [ i ] is a factor of n ; cnt = cnt + 1 ; incrementing power ; Calculating number of divisors If n = a ^ p * b ^ q then total divisors of n are ( p + 1 ) * ( q + 1 ) ; First case ; Second case ; Third casse ; return ans ; Total divisors ; Returns sum of all factors of n . ; Traversing through all prime factors . ; This condition is to handle the case when n is a prime number greater than 2. ; Check if number is Arithmetic Number or not . ; Driver code
using System ; class GFG { static void SieveOfEratosthenes ( int n , bool [ ] prime , bool [ ] primesquare , int [ ] a ) { for ( int i = 2 ; i <= n ; i ++ ) prime [ i ] = true ; for ( int i = 0 ; i <= ( n * n ) ; i ++ ) primesquare [ i ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } int j = 0 ; for ( int p = 2 ; p <= n ; p ++ ) { if ( prime [ p ] ) { a [ j ] = p ; primesquare [ p * p ] = true ; j ++ ; } } } static int countDivisors ( int n ) { if ( n == 1 ) return 1 ; bool [ ] prime = new bool [ n + 1 ] ; bool [ ] primesquare = new bool [ n * n + 1 ] ; SieveOfEratosthenes ( n , prime , primesquare , a ) ; int ans = 1 ; for ( int i = 0 ; ; i ++ ) { if ( a [ i ] * a [ i ] * a [ i ] > n ) break ; int cnt = 1 ; while ( n % a [ i ] == 0 ) { n = n / a [ i ] ; } ans = ans * cnt ; } if ( prime [ n ] ) ans = ans * 2 ; else if ( primesquare [ n ] ) ans = ans * 3 ; else if ( n != 1 ) ans = ans * 4 ; } 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 bool checkArithmetic ( int n ) { int count = countDivisors ( n ) ; int sum = sumofFactors ( n ) ; return ( sum % count == 0 ) ; } public static void Main ( String [ ] args ) { int n = 6 ; if ( checkArithmetic ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Finding n | A formula based C # program to find sum of series with cubes of first n natural numbers ; Driver Function
using System ; class GFG { static int magicOfSequence ( int N ) { return ( N * ( N + 1 ) / 2 ) + 2 * N ; } public static void Main ( ) { int N = 6 ; Console . Write ( magicOfSequence ( N ) ) ; } }
Form a number using corner digits of powers | C # program to find number formed by corner digits of powers . ; Find next power by multiplying N with current power ; Store digits of Power one by one . ; Calculate carry . ; Store carry in Power array . ; Prints number formed by corner digits of powers of N . ; Storing N raised to power 0 ; Initializing empty result ; One by one compute next powers and add their corner digits . ; Call Function that store power in Power array . ; Store unit and last digits of power in res . ; Driver Code
using System ; using System . Collections . Generic ; using System . Linq ; using System . Collections ; class GFG { static void nextPower ( int N , ref List < int > power ) { int carry = 0 ; for ( int i = 0 ; i < power . Count ; i ++ ) { int prod = ( power [ i ] * N ) + carry ; power [ i ] = prod % 10 ; carry = prod / 10 ; } while ( carry >= 1 ) { power . Add ( carry % 10 ) ; carry = carry / 10 ; } } static void printPowerNumber ( int X , int N ) { List < int > power = new List < int > ( ) ; power . Add ( 1 ) ; List < int > res = new List < int > ( ) ; for ( int i = 1 ; i <= X ; i ++ ) { nextPower ( N , ref power ) ; res . Add ( power . Last ( ) ) ; res . Add ( power . First ( ) ) ; } for ( int i = 0 ; i < res . Count ; i ++ ) Console . Write ( res [ i ] ) ; } public static void Main ( ) { int N = 19 , X = 4 ; printPowerNumber ( X , N ) ; } }
First digit in factorial of a number | A C # program for finding the First digit of the large factorial number ; Removing trailing 0 s as this does not change first digit . ; loop for divide the fact until it become the single digit and return the fact ; driver function
using System ; class GFG { static int firstDigit ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { fact = fact * i ; while ( fact % 10 == 0 ) fact = fact / 10 ; } while ( fact >= 10 ) fact = fact / 10 ; return fact ; } public static void Main ( ) { int n = 5 ; Console . Write ( firstDigit ( n ) ) ; } }
Sum of the series 1.2 . 3 + 2.3 . 4 + ... + n ( n + 1 ) ( n + 2 ) | Java program to find sum of the series 1.2 . 3 + 2.3 . 4 + 3.4 . 5 + ... ; Driver Code
using System ; class GFG { static int sumofseries ( int n ) { int res = 0 ; for ( int i = 1 ; i <= n ; i ++ ) res += ( i ) * ( i + 1 ) * ( i + 2 ) ; return res ; } public static void Main ( ) { Console . WriteLine ( sumofseries ( 3 ) ) ; } }
Find N Geometric Means between A and B | C # program to illustrate n geometric mean between A and B ; insert function for calculating the means ; Finding the value of R Common ration ; for finding N the Geometric mean between A and B ; Driver code
using System ; public class GFG { static void printGMeans ( int A , int B , int N ) { float R = ( float ) Math . Pow ( ( float ) ( B / A ) , 1.0 / ( float ) ( N + 1 ) ) ; for ( int i = 1 ; i <= N ; i ++ ) Console . Write ( A * Math . Pow ( R , i ) + " ▁ " ) ; } public static void Main ( ) { int A = 3 , B = 81 , N = 2 ; printGMeans ( A , B , N ) ; } }
Numbers having difference with digit sum more than s | C # Program to find number of integer such that integer - digSum > s ; function for digit sum ; function to calculate count of integer s . t . integer - digSum > s ; if n < s no integer possible ; iterate for s range and then calculate total count of such integer if starting integer is found ; if no integer found return 0 ; Driver program
using System ; class GFG { static long digitSum ( long n ) { long digSum = 0 ; while ( n > 0 ) { digSum += n % 10 ; n /= 10 ; } return digSum ; } public static long countInteger ( long n , long s ) { if ( n < s ) return 0 ; for ( long i = s ; i <= Math . Min ( n , s + 163 ) ; i ++ ) if ( ( i - digitSum ( i ) ) > s ) return ( n - i + 1 ) ; return 0 ; } public static void Main ( ) { long n = 1000 , s = 100 ; Console . WriteLine ( countInteger ( n , s ) ) ; } }
Division without using ' / ' operator | C # program to divide a number by other without using / operator ; Function to find division without using ' / ' operator ; Handling negative numbers ; if num1 is greater than equal to num2 subtract num2 from num1 and increase quotient by one . ; checking if neg equals to 1 then making quotient negative ; Driver Code
using System ; class GFG { static int division ( int num1 , int num2 ) { if ( num1 == 0 ) return 0 ; if ( num2 == 0 ) return int . MaxValue ; bool negResult = false ; if ( num1 < 0 ) { num1 = - num1 ; if ( num2 < 0 ) num2 = - num2 ; else negResult = true ; } else if ( num2 < 0 ) { num2 = - num2 ; negResult = true ; } int quotient = 0 ; while ( num1 >= num2 ) { num1 = num1 - num2 ; quotient ++ ; } if ( negResult ) quotient = - quotient ; return quotient ; } public static void Main ( ) { int num1 = 13 , num2 = 2 ; Console . Write ( division ( num1 , num2 ) ) ; } }
Nonagonal number | C # Program find first n nonagonal number . ; Function to find nonagonal number series . ; Driver Code
using System ; class GFG { static void Nonagonal ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { Console . Write ( i * ( 7 * i - 5 ) / 2 ) ; Console . Write ( " ▁ " ) ; } } public static void Main ( ) { int n = 10 ; Nonagonal ( n ) ; } }
Find n | C # program to calculate nth term of a series ; Function for calualtion ; For summation of square of first n - natural nos . ; summation of first n natural nos . ; return result ; Driver Code
using System ; class GFG { static int seriesFunc ( int n ) { int sumSquare = ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ; int sumNatural = ( n * ( n + 1 ) / 2 ) ; return ( sumSquare + sumNatural + 1 ) ; } public static void Main ( ) { int n = 8 ; Console . WriteLine ( seriesFunc ( n ) ) ; n = 13 ; Console . WriteLine ( seriesFunc ( 13 ) ) ; } }
Program to check Plus Perfect Number | C # implementation to check if the number is plus perfect or not ; function to check plus perfect number ; calculating number of digits ; calculating plus perfect number ; checking whether number is plus perfect or not ; Driver program
using System ; class GFG { static bool checkplusperfect ( int x ) { int temp = x ; int n = 0 ; while ( x != 0 ) { x /= 10 ; n ++ ; } x = temp ; int sum = 0 ; while ( x != 0 ) { sum += ( int ) Math . Pow ( x % 10 , n ) ; x /= 10 ; } return ( sum == temp ) ; } public static void Main ( ) { int x = 9474 ; if ( checkplusperfect ( x ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Number of distinct subsets of a set | C # program to count number of distinct subsets in an array of distinct numbers ; Returns 2 ^ n ; Driver program
using System ; class GFG { static int subsetCount ( int [ ] arr , int n ) { return 1 << n ; } public static void Main ( ) { int [ ] A = { 1 , 2 , 3 } ; int n = A . Length ; Console . WriteLine ( subsetCount ( A , n ) ) ; } }
Program to calculate GST from original and net prices | C # Program to compute GST from original and net prices . ; return value after calculate GST % ; Driver code
using System ; class GFG { static float Calculate_GST ( float org_cost , float N_price ) { return ( ( ( N_price - org_cost ) * 100 ) / org_cost ) ; } public static void Main ( ) { float org_cost = 100 ; float N_price = 120 ; Console . Write ( " ▁ GST ▁ = ▁ " + Calculate_GST ( org_cost , N_price ) + " % " ) ; } }
Centered hexagonal number | C # Program to find nth centered hexadecimal number ; Function to find centered hexadecimal number ; Formula to calculate nth centered hexadecimal number and return it into main function ; Driver Code
using System ; class GFG { static int centeredHexagonalNumber ( int n ) { return 3 * n * ( n - 1 ) + 1 ; } public static void Main ( ) { int n = 10 ; Console . Write ( n + " th ▁ centered ▁ " + " hexagonal ▁ number : ▁ " ) ; Console . Write ( centeredHexagonalNumber ( n ) ) ; } }
Find the distance covered to collect items at equal distances | C # program to calculate the distance for given problem ; function to calculate the distance ; Driver program
using System ; class GFG { public static int find_distance ( int n ) { return n * ( ( 3 * n ) + 7 ) ; } public static void Main ( ) { int n = 5 ; Console . Write ( find_distance ( n ) ) ; } }
Twin Prime Numbers | C # Code for Twin Prime Numbers ; Please refer below post for details of this function https : goo . gl / Wv3fGv ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Returns true if n1 and n2 are twin primes ; Driver program
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 twinPrime ( int n1 , int n2 ) { return ( isPrime ( n1 ) && isPrime ( n2 ) && Math . Abs ( n1 - n2 ) == 2 ) ; } public static void Main ( ) { int n1 = 11 , n2 = 13 ; if ( twinPrime ( n1 , n2 ) ) Console . WriteLine ( " Twin ▁ Prime " ) ; else Console . WriteLine ( " Not ▁ Twin ▁ Prime " ) ; } }
Sum of the sequence 2 , 22 , 222 , ... ... ... | C # Code for Sum of the sequence 2 , 22 , 222 , ... ; Function which return the the sum of series ; Driver Code
using System ; class GFG { static double sumOfSeries ( int n ) { return 0.0246 * ( Math . Pow ( 10 , n ) - 1 - ( 9 * n ) ) ; } public static void Main ( ) { int n = 3 ; Console . Write ( sumOfSeries ( n ) ) ; } }
Find sum of even index binomial coefficients | C # Program to find sum even indexed Binomial Coefficient . ; Returns value of even indexed Binomial Coefficient Sum which is 2 raised to power n - 1. ; Driver Code
using System ; class GFG { static int evenbinomialCoeffSum ( int n ) { return ( 1 << ( n - 1 ) ) ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( evenbinomialCoeffSum ( n ) ) ; } }
Program to print triangular number series till n | C # Program to print triangular number series till n ; Function to find triangular number ; For each iteration increase j by 1 and add it into k ; Increasing j by 1 ; Add value of j into k and update k ; Driver Code
using System ; class GFG { static void triangular_series ( int n ) { int i , j = 1 , k = 1 ; for ( i = 1 ; i <= n ; i ++ ) { Console . Write ( k + " ▁ " ) ; j += 1 ; k += j ; } } public static void Main ( ) { int n = 5 ; triangular_series ( n ) ; } }
Sum of the series 1 + ( 1 + 3 ) + ( 1 + 3 + 5 ) + ( 1 + 3 + 5 + 7 ) + Ã ¢ â ‚¬¦ Ã ¢ â ‚¬¦ + ( 1 + 3 + 5 + 7 + Ã ¢ â ‚¬¦ + ( 2 n | C # implementation to find the sum of the given series ; function to find the sum of the given series ; required sum ; Driver program to test above
using System ; class GfG { static int sumOfTheSeries ( int n ) { return ( n * ( n + 1 ) / 2 ) * ( 2 * n + 1 ) / 3 ; } public static void Main ( ) { int n = 5 ; Console . Write ( " Sum ▁ = ▁ " + sumOfTheSeries ( n ) ) ; } }
Sum of the series 1 + ( 1 + 2 ) + ( 1 + 2 + 3 ) + ( 1 + 2 + 3 + 4 ) + ... ... + ( 1 + 2 + 3 + 4 + ... + n ) | C # Code For Sum of the series ; Function to find sum of given series ; Driver program to test above function
using System ; class GFG { static int sumOfSeries ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= i ; j ++ ) sum += j ; return sum ; } public static void Main ( ) { int n = 10 ; Console . Write ( sumOfSeries ( n ) ) ; } }
Number of triangles after N moves | C # program to find middle of three distinct numbers to calculate the number of equilateral triangles ; function to calculate number of triangles in Nth step ; Driver code
using System ; class Triangle { public static double numberOfTriangles ( int n ) { double ans = 2 * ( Math . Pow ( 3 , n ) ) - 1 ; return ans ; } public static void Main ( ) { int n = 2 ; Console . WriteLine ( numberOfTriangles ( n ) ) ; } }
Motzkin number | C # Program to find Nth Motzkin Number . ; Return the nth Motzkin Number . ; Base case ; Finding i - th Motzkin number . ; driver code
using System ; class GFG { public static int motzkin ( int n ) { int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = dp [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) dp [ i ] = ( ( 2 * i + 1 ) * dp [ i - 1 ] + ( 3 * i - 3 ) * dp [ i - 2 ] ) / ( i + 2 ) ; return dp [ n ] ; } public static void Main ( ) { int n = 8 ; Console . WriteLine ( motzkin ( n ) ) ; } }
NicomachusÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢¢ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¡¬ ÃƒÆ ’ Ã † â €™¢ ÃƒÆ ’¢ Ãƒ ¢ Ã ¢ â ‚¬ Å ¡¬ Ãƒâ €¦¾¢ s Theorem ( Sum of k | Efficient C # code to find sum of k - th group of positive odd integers . ; Return the sum of kth group of positive odd integer . ; Driver program to test above methods
using System ; class GFG { public static int kthgroupsum ( int k ) { return k * k * k ; } public static void Main ( ) { int k = 3 ; Console . WriteLine ( kthgroupsum ( k ) ) ; } }
Find x , y , z that satisfy 2 / n = 1 / x + 1 / y + 1 / z | C # program to find x y z that satisfies 2 / n = 1 / x + 1 / y + 1 / z ... ; function to find x y and z that satisfy given equation . ; Driver program
using System ; class GFG { static void printXYZ ( int n ) { if ( n == 1 ) Console . WriteLine ( - 1 ) ; else { Console . WriteLine ( " x ▁ is ▁ " + n ) ; Console . WriteLine ( " y ▁ is ▁ " + ( n + 1 ) ) ; Console . WriteLine ( " z ▁ is ▁ " + ( n * ( n + 1 ) ) ) ; } } public static void Main ( ) { int n = 7 ; printXYZ ( n ) ; } }
Find n | C # program to find the n - th term in series 1 3 6 10 . . . ; Function to find nth term ; Driver Code
using System ; class GFG { static int term ( int n ) { return n * ( n + 1 ) / 2 ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( term ( n ) ) ; } }
Find Harmonic mean using Arithmetic mean and Geometric mean | C # implementation of compution of arithmetic mean , geometric mean and harmonic mean ; Function to calculate arithmetic mean , geometric mean and harmonic mean ; Driver function
using System ; class GeeksforGeeks { static double compute ( int a , int b ) { double AM , GM , HM ; AM = ( a + b ) / 2 ; GM = Math . Sqrt ( a * b ) ; HM = ( GM * GM ) / AM ; return HM ; } public static void Main ( ) { int a = 5 , b = 15 ; double HM = compute ( a , b ) ; Console . WriteLine ( " Harmonic ▁ Mean ▁ between ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + HM ) ; } }
Find n | C # program to find n - th element in the series 9 , 33 , 73 , 128. . ; Returns n - th element of the series ; driver function
using System ; class GFG { static int series ( int n ) { return ( 8 * n * n ) + 1 ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( series ( n ) ) ; } }
Check if a number is divisible by all prime divisors of another number | C # program to find if all prime factors of y divide x . ; Returns true if all prime factors of y divide x . ; Driver program to test above functions
using System ; class GFG { public static int gcd ( int a , int b ) { return b == 0 ? a : gcd ( b , a % b ) ; } static bool isDivisible ( int x , int y ) { if ( y == 1 ) return true ; int z = gcd ( x , y ) ; if ( z == 1 ) return false ; return isDivisible ( x , y / z ) ; } public static void Main ( ) { int x = 18 , y = 12 ; if ( isDivisible ( x , y ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Program to find Sum of a Series a ^ 1 / 1 ! + a ^ 2 / 2 ! + a ^ 3 / 3 ! + a ^ 4 / 4 ! + Ã ¢ â ‚¬¦ Ã ¢ â ‚¬¦ . + a ^ n / n ! | C # program to print the sum of series ; Function to calculate sum of given series ; multiply ( a / i ) to previous term ; store result in res
using System ; class GFG { public static void Main ( ) { double n = 5 , a = 2 ; Console . WriteLine ( sumOfSeries ( a , n ) ) ; } static float sumOfSeries ( double a , double n ) { double res = 0 , prev = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { prev *= ( a / i ) ; res = res + prev ; } return ( float ) ( res ) ; } }
Program for Celsius To Fahrenheit conversion | C # program to convert Celsius scale to Fahrenheit scale ; function to convert Celsius scale to Fahrenheit scale ; Driver code
using System ; class GFG { static float Cel_To_Fah ( float n ) { return ( ( n * 9.0f / 5.0f ) + 32.0f ) ; } public static void Main ( ) { float n = 20.0f ; Console . Write ( Cel_To_Fah ( n ) ) ; } }
Series with largest GCD and sum equals to n | C # program to find the series with largest GCD and sum equals to n ; function to generate and print the sequence ; stores the maximum gcd that can be possible of sequence . ; if maximum gcd comes out to be zero then not possible ; the smallest gcd possible is 1 ; traverse the array to find out the max gcd possible ; checks if the number is divisible or not ; checks if x is smaller then the max gcd possible and x is greater then the resultant gcd till now , then r = x ; checks if n / x is smaller than the max gcd possible and n / x is greater then the resultant gcd till now , then r = x ; traverses and prints d , 2d , 3d , ... , ( k - 1 ) ; computes the last element of the sequence n - s . ; prints the last element ; Driver Code
using System ; class GFG { static void print_sequence ( int n , int k ) { int b = n / ( k * ( k + 1 ) / 2 ) ; if ( b == 0 ) { Console . Write ( " - 1" ) ; } else { int r = 1 ; for ( int x = 1 ; x * x <= n ; x ++ ) { if ( n % x != 0 ) continue ; if ( x <= b && x > r ) r = x ; if ( n / x <= b && n / x > r ) r = n / x ; } for ( int i = 1 ; i < k ; i ++ ) Console . Write ( r * i + " ▁ " ) ; int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ; Console . WriteLine ( res ) ; } } public static void Main ( ) { int n = 24 ; int k = 4 ; print_sequence ( n , k ) ; n = 24 ; k = 5 ; print_sequence ( n , k ) ; n = 6 ; k = 4 ; print_sequence ( n , k ) ; } }
Number of compositions of a natural number | C # program to find the total number of compositions of a natural number ; Return 2 raised to power ( n - 1 ) ; Driver Code
using System ; class GFG { public static int countCompositions ( int n ) { return 1 << ( n - 1 ) ; } public static void Main ( ) { int n = 4 ; Console . Write ( countCompositions ( n ) ) ; } }