"Products of ranges in an array | Product in range Queries in O ( N ) ; Function to calculate Product in the given range . ; As our array is 0 based as and L and R are given as 1 based index . ; Driver code"
Solution in C#:

using System ; class GFG { static int calculateProduct ( int [ ] A , int L , int R , int P ) { L = L - 1 ; R = R - 1 ; int ans = 1 ; for ( int i = L ; i <= R ; i ++ ) { ans = ans * A [ i ] ; ans = ans % P ; } return ans ; } static public void Main ( ) { int [ ] A = { 1 , 2 , 3 , 4 , 5 , 6 } ; int P = 229 ; int L = 2 , R = 5 ; Console . WriteLine ( calculateProduct ( A , L , R , P ) ) ; L = 1 ; R = 3 ; Console . WriteLine ( calculateProduct ( A , L , R , P ) ) ; } }


"Program To Check whether a Triangle is Equilateral , Isosceles or Scalene | C # program for the above approach ; Function to check if the triangle is equilateral or isosceles or scalene ; Check for equilateral triangle ; Check for isosceles triangle ; Otherwise scalene triangle ; Driver Code ; Given sides of triangle ; Function call"
Solution in C#:

using System ; class GFG { static void checkTriangle ( int x , int y , int z ) { if ( x == y && y == z ) Console . WriteLine ( " Equilateral ▁ Triangle " ) ; else if ( x == y y == z z == x ) Console . WriteLine ( " Isosceles ▁ Triangle " ) ; else Console . WriteLine ( " Scalene ▁ Triangle " ) ; } public static void Main ( ) { int x = 8 , y = 7 , z = 9 ; checkTriangle ( x , y , z ) ; } }


"Program for Area And Perimeter Of Rectangle | C # program to find area and perimeter of rectangle ; Utility function ; Driver Function"
Solution in C#:

using System ; class GFG { static int areaRectangle ( int a , int b ) { int area = a * b ; return area ; } static int perimeterRectangle ( int a , int b ) { int perimeter = 2 * ( a + b ) ; return perimeter ; } public static void Main ( ) { int a = 5 ; int b = 6 ; Console . WriteLine ( " Area ▁ = ▁ " + areaRectangle ( a , b ) ) ; Console . WriteLine ( " Perimeter ▁ = ▁ " + perimeterRectangle ( a , b ) ) ; } }


"Program for Area Of Square after N | C # program to find the area of the square ; Function to calculate area of square after given number of folds ; Driver Code"
Solution in C#:

using System ; class GFG { static double areaSquare ( double side , double fold ) { double area = side * side ; return area * 1.0 / Math . Pow ( 2 , fold ) ; } public static void Main ( ) { double side = 4 , fold = 2 ; Console . Write ( areaSquare ( side , fold ) ) ; } }


"Program for Area Of Square | C # program to find the area of the square ; Driver code"
Solution in C#:

using System ; class GFG { static int areaSquare ( int side ) { int area = side * side ; return area ; } public static void Main ( ) { int side = 4 ; Console . WriteLine ( areaSquare ( side ) ) ; } }


"Program for Armstrong Numbers |"
Solution in C#:

using System ; public class armstrongNumber { public void isArmstrong ( String n ) { char [ ] s = n . ToCharArray ( ) ; int size = s . Length ; int sum = 0 ; foreach ( char num in s ) { int temp = 1 ; int i = Int32 . Parse ( char . ToString ( num ) ) ; for ( int j = 0 ; j <= size - 1 ; j ++ ) { temp *= i ; } sum += temp ; } if ( sum == Int32 . Parse ( n ) ) { Console . WriteLine ( " True " ) ; } else { Console . WriteLine ( " False " ) ; } } public static void Main ( String [ ] args ) { armstrongNumber am = new armstrongNumber ( ) ; am . isArmstrong ( "153" ) ; am . isArmstrong ( "231" ) ; } }


"Program for Best Fit algorithm in Memory Management | C # implementation of Best - Fit algorithm ; Method to allocate memory to blocks as per Best fit algorithm ; Stores block id of the block allocated to a process ; Initially no block is assigned to any process ; pick each process and find suitable blocks according to its size ad assign to it ; Find the best fit block for current process ; If we could find a block for current process ; allocate block j to p [ i ] process ; Reduce available memory in this block . ; Driver Method"
Solution in C#:

 using System ; public class GFG { static void bestFit ( int [ ] blockSize , int m , int [ ] processSize , int n ) { int [ ] allocation = new int [ n ] ; for ( int i = 0 ; i < allocation . Length ; i ++ ) allocation [ i ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int bestIdx = - 1 ; for ( int j = 0 ; j < m ; j ++ ) { if ( blockSize [ j ] >= processSize [ i ] ) { if ( bestIdx == - 1 ) bestIdx = j ; else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ; } } if ( bestIdx != - 1 ) { allocation [ i ] = bestIdx ; blockSize [ bestIdx ] -= processSize [ i ] ; } } Console . WriteLine ( "
 Process ▁ No . 	 Process " + " ▁ Size 	 Block ▁ no . " ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( " ▁ " + ( i + 1 ) + " 	 	 " + processSize [ i ] + " 	 	 " ) ; if ( allocation [ i ] != - 1 ) Console . Write ( allocation [ i ] + 1 ) ; else Console . Write ( " Not ▁ Allocated " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int [ ] blockSize = { 100 , 500 , 200 , 300 , 600 } ; int [ ] processSize = { 212 , 417 , 112 , 426 } ; int m = blockSize . Length ; int n = processSize . Length ; bestFit ( blockSize , m , processSize , n ) ; } }


"Program for Binary To Decimal Conversion | Function to convert binary to decimal ; Initializing base1 value to 1 , i . e 2 ^ 0 ; Driver Code"
Solution in C#:

class GFG { public static int binaryToDecimal ( int n ) { int num = n ; int dec_value = 0 ; int base1 = 1 ; int temp = num ; while ( temp > 0 ) { int last_digit = temp % 10 ; temp = temp / 10 ; dec_value += last_digit * base1 ; base1 = base1 * 2 ; } return dec_value ; } public static void Main ( ) { int num = 10101001 ; System . Console . Write ( binaryToDecimal ( num ) ) ; } }


"Program for Binomial Coefficients table | C # program for binomial coefficients ; Function to print binomial table ; B ( m , x ) is 1 if either m or x is is 0. ; Otherwise using recursive formula B ( m , x ) = B ( m , x - 1 ) * ( m - x + 1 ) / x ; Driver Function"
Solution in C#:

using System ; public class GFG { static void printbinomial ( int max ) { for ( int m = 0 ; m <= max ; m ++ ) { Console . Write ( m + " ▁ " ) ; int binom = 1 ; for ( int x = 0 ; x <= m ; x ++ ) { if ( m != 0 && x != 0 ) binom = binom * ( m - x + 1 ) / x ; Console . Write ( binom + " ▁ " ) ; } Console . WriteLine ( ) ; } } static public void Main ( ) { int max = 10 ; printbinomial ( max ) ; } }


"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"
Solution in C#:

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 ) ) ; } }


"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"
Solution in C#:

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 ) ) ; } }


"Program for Chocolate and Wrapper Puzzle | Efficient C # program to find maximum number of chocolates ; Returns maximum number of chocolates we can eat with given money , price of chocolate and number of wrapprices required to get a chocolate . ; Corner case ; First find number of chocolates that can be purchased with the given amount ; Now just add number of chocolates with the chocolates gained by wrapprices ; Driver code ; total money ; cost of each candy ; no of wrappers needs to be ; exchanged for one chocolate ."
Solution in C#:

using System ; class GFG { static int countMaxChoco ( int money , int price , int wrap ) { if ( money < price ) return 0 ; int choc = money / price ; choc = choc + ( choc - 1 ) / ( wrap - 1 ) ; return choc ; } public static void Main ( ) { int money = 15 ; int price = 1 ; int wrap = 3 ; Console . WriteLine ( countMaxChoco ( money , price , wrap ) ) ; } }


"Program for Decimal to Binary Conversion | C # implementation of the approach ; Function to return the binary equivalent of decimal value N ; To store the binary number ; Count used to store exponent value ; Driver code"
Solution in C#:

using System ; class GFG { static int decimalToBinary ( int N ) { int B_Number = 0 ; int cnt = 0 ; while ( N != 0 ) { int rem = N % 2 ; int c = ( int ) Math . Pow ( 10 , cnt ) ; B_Number += rem * c ; N /= 2 ; cnt ++ ; } return B_Number ; } static public void Main ( ) { int N = 17 ; Console . Write ( decimalToBinary ( N ) ) ; } }


"Program for Decimal to Binary Conversion | C # program to convert a decimal number to binary number ; function to convert decimal to binary ; array to store binary number ; counter for binary array ; storing remainder in binary array ; printing binary array in reverse order ; Driver Code"
Solution in C#:

using System ; public class GFG { static void decToBinary ( int n ) { int [ ] binaryNum = new int [ 32 ] ; int i = 0 ; while ( n > 0 ) { binaryNum [ i ] = n % 2 ; n = n / 2 ; i ++ ; } for ( int j = i - 1 ; j >= 0 ; j -- ) Console . Write ( binaryNum [ j ] ) ; } public static void Main ( ) { int n = 17 ; decToBinary ( n ) ; } }


"Program for First Fit algorithm in Memory Management | C # implementation of First - Fit algorithm ; Method to allocate memory to blocks as per First fit algorithm ; Stores block id of the block allocated to a process ; Initially no block is assigned to any process ; pick each process and find suitable blocks according to its size ad assign to it ; allocate block j to p [ i ] process ; Reduce available memory in this block . ; Driver Code"
Solution in C#:

 using System ; class GFG { static void firstFit ( int [ ] blockSize , int m , int [ ] processSize , int n ) { int [ ] allocation = new int [ n ] ; for ( int i = 0 ; i < allocation . Length ; i ++ ) allocation [ i ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( blockSize [ j ] >= processSize [ i ] ) { allocation [ i ] = j ; blockSize [ j ] -= processSize [ i ] ; break ; } } } Console . WriteLine ( "
 Process ▁ No . 	 Process ▁ Size 	 Block ▁ no . " ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( " ▁ " + ( i + 1 ) + " 	 	 " + processSize [ i ] + " 	 	 " ) ; if ( allocation [ i ] != - 1 ) Console . Write ( allocation [ i ] + 1 ) ; else Console . Write ( " Not ▁ Allocated " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int [ ] blockSize = { 100 , 500 , 200 , 300 , 600 } ; int [ ] processSize = { 212 , 417 , 112 , 426 } ; int m = blockSize . Length ; int n = processSize . Length ; firstFit ( blockSize , m , processSize , n ) ; } }


"Program for Gauss | C # Implementation for Gauss - Jordan Elimination Method ; Function to print the matrix ; function to reduce matrix to reduced row echelon form . ; Performing elementary operations ; Excluding all i == j ; Converting Matrix to reduced row echelon form ( diagonal matrix ) ; Function to print the desired result if unique solutions exists , otherwise prints no solution or infinite solutions depending upon the input given . ; Printing the solution by dividing constants by their respective diagonal elements ; To check whether infinite solutions exists or no solution exists ; flag == 2 for infinite solution flag == 3 for No solution ; Driver code ; Order of Matrix ( n ) ; Performing Matrix transformation ; Printing Final Matrix ; Printing Solutions ( if exist )"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static int M = 10 ; static void PrintMatrix ( float [ , ] a , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) Console . Write ( a [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } static int PerformOperation ( float [ , ] a , int n ) { int i , j , k = 0 , c , flag = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a [ i , i ] == 0 ) { c = 1 ; while ( ( i + c ) < n && a [ i + c , i ] == 0 ) c ++ ; if ( ( i + c ) == n ) { flag = 1 ; break ; } for ( j = i , k = 0 ; k <= n ; k ++ ) { float temp = a [ j , k ] ; a [ j , k ] = a [ j + c , k ] ; a [ j + c , k ] = temp ; } } for ( j = 0 ; j < n ; j ++ ) { if ( i != j ) { float p = a [ j , i ] / a [ i , i ] ; for ( k = 0 ; k <= n ; k ++ ) a [ j , k ] = a [ j , k ] - ( a [ i , k ] ) * p ; } } } return flag ; } static void PrintResult ( float [ , ] a , int n , int flag ) { Console . Write ( " Result ▁ is ▁ : ▁ " ) ; if ( flag == 2 ) Console . WriteLine ( " Infinite ▁ Solutions ▁ Exists " ) ; else if ( flag == 3 ) Console . WriteLine ( " No ▁ Solution ▁ Exists " ) ; else { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( a [ i , n ] / a [ i , i ] + " ▁ " ) ; } } static int CheckConsistency ( float [ , ] a , int n , int flag ) { int i , j ; float sum ; flag = 3 ; for ( i = 0 ; i < n ; i ++ ) { sum = 0 ; for ( j = 0 ; j < n ; j ++ ) sum = sum + a [ i , j ] ; if ( sum == a [ i , j ] ) flag = 2 ; } return flag ; } public static void Main ( String [ ] args ) { float [ , ] a = { { 0 , 2 , 1 , 4 } , { 1 , 1 , 2 , 6 } , { 2 , 1 , 1 , 7 } } ; int n = 3 , flag = 0 ; flag = PerformOperation ( a , n ) ; if ( flag == 1 ) flag = CheckConsistency ( a , n , flag ) ; Console . WriteLine ( " Final ▁ Augumented ▁ Matrix ▁ is ▁ : ▁ " ) ; PrintMatrix ( a , n ) ; Console . WriteLine ( " " ) ; PrintResult ( a , n , flag ) ; } }


"Program for Identity Matrix | C # program to check if a given matrix is identity ; Driver Code"
Solution in C#:

using System ; class GFG { int MAX = 100 ; static bool isIdentity ( int [ , ] mat , int N ) { for ( int row = 0 ; row < N ; row ++ ) { for ( int col = 0 ; col < N ; col ++ ) { if ( row == col && mat [ row , col ] != 1 ) return false ; else if ( row != col && mat [ row , col ] != 0 ) return false ; } } return true ; } public static void Main ( ) { int N = 4 ; int [ , ] mat = { { 1 , 0 , 0 , 0 } , { 0 , 1 , 0 , 0 } , { 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 1 } } ; if ( isIdentity ( mat , N ) ) Console . WriteLine ( " Yes ▁ " ) ; else Console . WriteLine ( " No ▁ " ) ; } }


"Program for Identity Matrix | C # program to print Identity Matrix ; Checking if row is equal to column ; Driver Code"
Solution in C#:

using System ; class GFG { static int identity ( int num ) { int row , col ; for ( row = 0 ; row < num ; row ++ ) { for ( col = 0 ; col < num ; col ++ ) { if ( row == col ) Console . Write ( 1 + " ▁ " ) ; else Console . Write ( 0 + " ▁ " ) ; } Console . WriteLine ( ) ; } return 0 ; } public static void Main ( ) { int size = 5 ; identity ( size ) ; } }


"Program for Least Recently Used ( LRU ) Page Replacement algorithm | C # implementation of above algorithm ; Method to find page faults using indexes ; To represent set of current pages . We use an unordered_set so that we quickly check if a page is present in set or not ; To store least recently used indexes of pages . ; Start from initial page ; Check if the set can hold more pages ; Insert it into set if not present already which represents page fault ; increment page fault ; Store the recently used index of each page ; If the set is full then need to perform lru i . e . remove the least recently used page and insert the current page ; Check if current page is not already present in the set ; Find the least recently used pages that is present in the set ; Remove the indexes page ; remove lru from hashmap ; insert the current page ; Increment page faults ; Update the current page index ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static int pageFaults ( int [ ] pages , int n , int capacity ) { HashSet < int > s = new HashSet < int > ( capacity ) ; Dictionary < int , int > indexes = new Dictionary < int , int > ( ) ; int page_faults = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . Count < capacity ) { if ( ! s . Contains ( pages [ i ] ) ) { s . Add ( pages [ i ] ) ; page_faults ++ ; } if ( indexes . ContainsKey ( pages [ i ] ) ) indexes [ pages [ i ] ] = i ; else indexes . Add ( pages [ i ] , i ) ; } else { if ( ! s . Contains ( pages [ i ] ) ) { int lru = int . MaxValue , val = int . MinValue ; foreach ( int itr in s ) { int temp = itr ; if ( indexes [ temp ] < lru ) { lru = indexes [ temp ] ; val = temp ; } } s . Remove ( val ) ; indexes . Remove ( val ) ; s . Add ( pages [ i ] ) ; page_faults ++ ; } if ( indexes . ContainsKey ( pages [ i ] ) ) indexes [ pages [ i ] ] = i ; else indexes . Add ( pages [ i ] , i ) ; } } return page_faults ; } public static void Main ( String [ ] args ) { int [ ] pages = { 7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 } ; int capacity = 4 ; Console . WriteLine ( pageFaults ( pages , pages . Length , capacity ) ) ; } }


"Program for Least Recently Used ( LRU ) Page Replacement algorithm | C # program for page replacement algorithms ; Driver method ; To represent set of current pages . We use an Arraylist ; Insert it into set if not present already which represents page fault ; Check if the set can hold equal pages ; Increment page faults ; Remove the indexes page ; insert the current page"
Solution in C#:

using System ; using System . Collections . Generic ; class LRU { public static void Main ( String [ ] args ) { int capacity = 4 ; int [ ] arr = { 7 , 0 , 1 , 2 , 0 , 3 , 0 , 4 , 2 , 3 , 0 , 3 , 2 } ; List < int > s = new List < int > ( capacity ) ; int count = 0 ; int page_faults = 0 ; foreach ( int i in arr ) { if ( ! s . Contains ( i ) ) { if ( s . Count == capacity ) { s . RemoveAt ( 0 ) ; s . Insert ( capacity - 1 , i ) ; } else s . Insert ( count , i ) ; page_faults ++ ; ++ count ; } else { s . Remove ( i ) ; s . Insert ( s . Count , i ) ; } } Console . WriteLine ( page_faults ) ; } }


"Program for Markov matrix | C # code to check Markov Matrix ; outer loop to access rows and inner to access columns ; Find sum of current row ; Driver Code ; Matrix to check ; calls the function check ( )"
Solution in C#:

using System ; class GFG { static bool checkMarkov ( double [ , ] m ) { for ( int i = 0 ; i < m . GetLength ( 0 ) ; i ++ ) { double sum = 0 ; for ( int j = 0 ; j < m . GetLength ( 1 ) ; j ++ ) sum = sum + m [ i , j ] ; if ( sum != 1 ) return false ; } return true ; } static void Main ( ) { double [ , ] m = new double [ , ] { { 0 , 0 , 1 } , { 0.5 , 0 , 0.5 } , { 1 , 0 , 0 } } ; if ( checkMarkov ( m ) ) Console . WriteLine ( " ▁ yes ▁ " ) ; else Console . WriteLine ( " ▁ no ▁ " ) ; } }


"Program for Mean Absolute Deviation | C # Program to find mean absolute deviation of given array ; Function to find mean of the array elements . ; Calculate sum of all elements . ; Function to find mean absolute deviation of given elements . ; Calculate the sum of absolute deviation about mean . ; Return mean absolute deviation about mean . ; Driver function ."
Solution in C#:

using System ; class GFG { static float Mean ( float [ ] arr , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; return sum / n ; } static float meanAbsDevtion ( float [ ] arr , int n ) { float absSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) absSum = absSum + Math . Abs ( arr [ i ] - Mean ( arr , n ) ) ; return absSum / n ; } public static void Main ( ) { float [ ] arr = { 10 , 15 , 15 , 17 , 18 , 21 } ; int n = arr . Length ; Console . WriteLine ( meanAbsDevtion ( arr , n ) ) ; } }


"Program for Mean and median of an unsorted array | C # program to find mean and median of an array ; Function for calculating mean ; Function for calculating median ; First we sort the array ; check for even case ; Driver Code ; Function call"
Solution in C#:

 using System ; class GFG { public static double findMean ( int [ ] a , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; return ( double ) sum / ( double ) n ; } public static double findMedian ( int [ ] a , int n ) { Array . Sort ( a ) ; if ( n % 2 != 0 ) return ( double ) a [ n / 2 ] ; return ( double ) ( a [ ( n - 1 ) / 2 ] + a [ n / 2 ] ) / 2.0 ; } public static void Main ( ) { int [ ] a = { 1 , 3 , 4 , 2 , 7 , 5 , 8 , 6 } ; int n = a . Length ; Console . Write ( " Mean ▁ = ▁ " + findMean ( a , n ) + "
 " ) ; Console . Write ( " Median ▁ = ▁ " + findMedian ( a , n ) + "
 " ) ; } }


"Program for Method Of False Position | C # program for implementation of Bisection Method for solving equations ; An example function whose solution is determined using Bisection Method . The function is x ^ 3 - x ^ 2 + 2 ; Prints root of func ( x ) in interval [ a , b ] ; Initialize result ; Find the point that touches x axis ; Check if the above found point is root ; Decide the side to repeat the steps ; Driver program ; Initial values assumed"
Solution in C#:

using System ; class GFG { static int MAX_ITER = 1000000 ; static double func ( double x ) { return ( x * x * x - x * x + 2 ) ; } static void regulaFalsi ( double a , double b ) { if ( func ( a ) * func ( b ) >= 0 ) { Console . WriteLine ( " You ▁ have ▁ not ▁ assumed ▁ right ▁ a ▁ and ▁ b " ) ; } double c = a ; for ( int i = 0 ; i < MAX_ITER ; i ++ ) { c = ( a * func ( b ) - b * func ( a ) ) / ( func ( b ) - func ( a ) ) ; if ( func ( c ) == 0 ) break ; else if ( func ( c ) * func ( a ) < 0 ) b = c ; else a = c ; } Console . WriteLine ( " The ▁ value ▁ of ▁ root ▁ is ▁ : ▁ " + ( int ) c ) ; } public static void Main ( String [ ] args ) { double a = - 200 , b = 300 ; regulaFalsi ( a , b ) ; } }


"Program for Mobius Function | C # program to print all prime factors ; Returns value of mobius ( ) ; Handling 2 separately ; If 2 ^ 2 also divides N ; Check for all other prime factors ; If i divides n ; If i ^ 2 also divides N ; Driver Code"
Solution in C#:

using System ; class GFG { static int mobius ( int n ) { int p = 0 ; if ( n % 2 == 0 ) { n = n / 2 ; p ++ ; if ( n % 2 == 0 ) return 0 ; } for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i = i + 2 ) { if ( n % i == 0 ) { n = n / i ; p ++ ; if ( n % i == 0 ) return 0 ; } } return ( p % 2 == 0 ) ? - 1 : 1 ; } public static void Main ( ) { int N = 17 ; Console . WriteLine ( " Mobius ▁ Functions " + " ▁ M ( N ) ▁ at ▁ N ▁ = ▁ " + N + " ▁ is : ▁ " + mobius ( N ) ) ; Console . WriteLine ( " Mobius ▁ Functions " + " M ( N ) ▁ at ▁ N ▁ = ▁ " + 25 + " ▁ is : ▁ " + mobius ( 25 ) ) ; Console . WriteLine ( " Mobius ▁ Functions " + " M ( N ) ▁ at ▁ N ▁ = ▁ " + 6 + " ▁ is : ▁ " + mobius ( 6 ) ) ; } }


"Program for Mobius Function | Set 2 | C # implementation of the approach ; Function to calculate least prime factor of each number ; If it is a prime number ; For all multiples which are not visited yet . ; Function to find the value of Mobius function for all the numbers from 1 to n ; To store the values of Mobius function ; If number is one ; If number has a squared prime factor ; Multiply - 1 with the previous number ; Driver code ; Function to find least prime factor ; Function to find mobius function"
Solution in C#:

using System ; class GFG { static int N = 100005 ; static int [ ] lpf = new int [ N ] ; static void least_prime_factor ( ) { for ( int i = 2 ; i < N ; i ++ ) if ( lpf [ i ] % 2 != 1 ) for ( int j = i ; j < N ; j += i ) if ( lpf [ j ] % 2 != 0 ) lpf [ j ] = i ; } static void Mobius ( int n ) { int [ ] mobius = new int [ N ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( i == 1 ) mobius [ i ] = 1 ; else { if ( lpf [ i / lpf [ i ] ] == lpf [ i ] ) mobius [ i ] = 0 ; else mobius [ i ] = - 1 * mobius [ i / lpf [ i ] ] ; } } for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( mobius [ i ] + " ▁ " ) ; } static public void Main ( ) { int n = 5 ; Array . Fill ( lpf , - 1 ) ; least_prime_factor ( ) ; Mobius ( n ) ; } }


"Program for Muller Method | C # Program to find root of a function , f ( x ) ; function to calculate f ( x ) ; Taking f ( x ) = x ^ 3 + 2 x ^ 2 + 10 x - 20 ; Calculating various constants required to calculate x3 ; Taking the root which is closer to x2 ; checking for resemblance of x3 with x2 till two decimal places ; Driver main function"
Solution in C#:

using System ; class Muller1 { static int MAX_ITERATIONS = 10000 ; static double f ( double x ) { return 1 * Math . Pow ( x , 3 ) + 2 * x * x + 10 * x - 20 ; } static void Muller ( double a , double b , double c ) { int i ; double res ; for ( i = 0 ; ; ++ i ) { double f1 = f ( a ) ; double f2 = f ( b ) ; double f3 = f ( c ) ; double d1 = f1 - f3 ; double d2 = f2 - f3 ; double h1 = a - c ; double h2 = b - c ; double a0 = f3 ; double a1 = ( ( ( d2 * Math . Pow ( h1 , 2 ) ) - ( d1 * Math . Pow ( h2 , 2 ) ) ) / ( ( h1 * h2 ) * ( h1 - h2 ) ) ) ; double a2 = ( ( ( d1 * h2 ) - ( d2 * h1 ) ) / ( ( h1 * h2 ) * ( h1 - h2 ) ) ) ; double x = ( ( - 2 * a0 ) / ( a1 + Math . Abs ( Math . Sqrt ( a1 * a1 - 4 * a0 * a2 ) ) ) ) ; double y = ( ( - 2 * a0 ) / ( a1 - Math . Abs ( Math . Sqrt ( a1 * a1 - 4 * a0 * a2 ) ) ) ) ; if ( x >= y ) res = x + c ; else res = y + c ; double m = res * 100 ; double n = c * 100 ; m = Math . Floor ( m ) ; n = Math . Floor ( n ) ; if ( m == n ) break ; a = b ; b = c ; c = res ; if ( i > MAX_ITERATIONS ) { Console . WriteLine ( " Root ▁ cannot ▁ be ▁ found ▁ using " + " ▁ Muller ' s ▁ method " ) ; break ; } } if ( i <= MAX_ITERATIONS ) Console . WriteLine ( " The ▁ value ▁ of ▁ the ▁ root ▁ is ▁ " + Math . Round ( res , 4 ) ) ; } static void Main ( ) { double a = 0 , b = 1 , c = 2 ; Muller ( a , b , c ) ; } }


"Program for N | C # program to find nth term of Arithmetic progression ; using formula to find the Nth term t ( n ) = a ( 1 ) + ( n - 1 ) * d ; Driver code ; starting number ; Common difference ; N th term to be find ; Display the output"
Solution in C#:

using System ; class GFG { public static int Nth_of_AP ( int a , int d , int N ) { return ( a + ( N - 1 ) * d ) ; } public static void Main ( ) { int a = 2 ; int d = 1 ; int N = 5 ; Console . WriteLine ( " The ▁ " + N + " th ▁ term ▁ of ▁ the ▁ series ▁ is ▁ : ▁ " + Nth_of_AP ( a , d , N ) ) ; } }


"Program for Newton Raphson Method | C # program for implementation of Newton Raphson Method for solving equations ; An example function whose solution is determined using Bisection Method . The function is x ^ 3 - x ^ 2 + 2 ; Derivative of the above function which is 3 * x ^ x - 2 * x ; Function to find the root ; x ( i + 1 ) = x ( i ) - f ( x ) / f '(x) ; Driver code ; Initial values assumed"
Solution in C#:

using System ; class GFG { static double EPSILON = 0.001 ; static double func ( double x ) { return x * x * x - x * x + 2 ; } static double derivFunc ( double x ) { return 3 * x * x - 2 * x ; } static void newtonRaphson ( double x ) { double h = func ( x ) / derivFunc ( x ) ; while ( Math . Abs ( h ) >= EPSILON ) { h = func ( x ) / derivFunc ( x ) ; x = x - h ; } Console . Write ( " The ▁ value ▁ of ▁ the " + " ▁ root ▁ is ▁ : ▁ " + Math . Round ( x * 100.0 ) / 100.0 ) ; } public static void Main ( ) { double x0 = - 20 ; newtonRaphson ( x0 ) ; } }


"Program for Next Fit algorithm in Memory Management | C # program for next fit memory management algorithm ; Function to allocate memory to blocks as per Next fit algorithm ; Stores block id of the block allocated to a process ; Initially no block is assigned to any process ; pick each process and find suitable blocks according to its size ad assign to it ; Do not start from beginning ; allocate block j to p [ i ] process ; Reduce available memory in this block . ; mod m will help in traversing the blocks from starting block after we reach the end . ; Driver program"
Solution in C#:

 using System ; using System . Linq ; public class GFG { static void NextFit ( int [ ] blockSize , int m , int [ ] processSize , int n ) { int [ ] allocation = new int [ n ] ; int j = 0 ; Enumerable . Repeat ( - 1 , n ) . ToArray ( ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( j < m ) { if ( blockSize [ j ] >= processSize [ i ] ) { allocation [ i ] = j ; blockSize [ j ] -= processSize [ i ] ; break ; } j = ( j + 1 ) % m ; } } Console . Write ( "
 Process ▁ No . 	 Process ▁ Size 	 Block ▁ no .
 " ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( i + 1 + " 	 	 " + processSize [ i ] + " 	 	 " ) ; if ( allocation [ i ] != - 1 ) { Console . Write ( allocation [ i ] + 1 ) ; } else { Console . Write ( " Not ▁ Allocated " ) ; } Console . WriteLine ( " " ) ; } } static public void Main ( ) { int [ ] blockSize = { 5 , 10 , 20 } ; int [ ] processSize = { 10 , 20 , 5 } ; int m = blockSize . Length ; int n = processSize . Length ; NextFit ( blockSize , m , processSize , n ) ; } }


"Program for Perrin numbers | Optimized C # program for n 'th perrin number ; Driver code"
Solution in C#:

using System ; class GFG { static int per ( int n ) { int a = 3 , b = 0 , c = 2 ; int m = 0 ; if ( n == 0 ) return a ; if ( n == 1 ) return b ; if ( n == 2 ) return c ; while ( n > 2 ) { m = a + b ; a = b ; b = c ; c = m ; n -- ; } return m ; } public static void Main ( ) { int n = 9 ; Console . WriteLine ( per ( n ) ) ; } }


"Program for Point of Intersection of Two Lines | C # Implementation . To find the point of intersection of two lines ; Class used to used to store the X and Y coordinates of a point respectively ; Method used to display X and Y coordinates of a point ; Line AB represented as a1x + b1y = c1 ; Line CD represented as a2x + b2y = c2 ; The lines are parallel . This is simplified by returning a pair of FLT_MAX ; Driver method ; NOTE : Further check can be applied in case of line segments . Here , we have considered AB and CD as lines"
Solution in C#:

using System ; public class Point { public double x , y ; public Point ( double x , double y ) { this . x = x ; this . y = y ; } public static void displayPoint ( Point p ) { Console . WriteLine ( " ( " + p . x + " , ▁ " + p . y + " ) " ) ; } } public class Test { public static Point lineLineIntersection ( Point A , Point B , Point C , Point D ) { double a1 = B . y - A . y ; double b1 = A . x - B . x ; double c1 = a1 * ( A . x ) + b1 * ( A . y ) ; double a2 = D . y - C . y ; double b2 = C . x - D . x ; double c2 = a2 * ( C . x ) + b2 * ( C . y ) ; double determinant = a1 * b2 - a2 * b1 ; if ( determinant == 0 ) { return new Point ( double . MaxValue , double . MaxValue ) ; } else { double x = ( b2 * c1 - b1 * c2 ) / determinant ; double y = ( a1 * c2 - a2 * c1 ) / determinant ; return new Point ( x , y ) ; } } public static void Main ( string [ ] args ) { Point A = new Point ( 1 , 1 ) ; Point B = new Point ( 4 , 4 ) ; Point C = new Point ( 1 , 8 ) ; Point D = new Point ( 2 , 4 ) ; Point intersection = lineLineIntersection ( A , B , C , D ) ; if ( intersection . x == double . MaxValue && intersection . y == double . MaxValue ) { Console . WriteLine ( " The ▁ given ▁ lines ▁ AB ▁ and ▁ CD ▁ are ▁ parallel . " ) ; } else { Console . Write ( " The ▁ intersection ▁ of ▁ the ▁ given ▁ lines ▁ AB ▁ " + " and ▁ CD ▁ is : ▁ " ) ; Point . displayPoint ( intersection ) ; } } }


"Program for Rank of Matrix | C # program to find rank of a matrix ; function for exchanging two rows of a matrix ; function for finding rank of matrix ; Before we visit current row ' row ' , we make sure that mat [ row ] [ 0 ] , ... . mat [ row ] [ row - 1 ] are 0. Diagonal element is not zero ; This makes all entries of current column as 0 except entry ' mat [ row ] [ row ] ' ; Diagonal element is already zero . Two cases arise : 1 ) If there is a row below it with non - zero entry , then swap this row with that row and process that row 2 ) If all elements in current column below mat [ r ] [ row ] are 0 , then remvoe this column by swapping it with last column and reducing number of columns by 1. ; Find the non - zero element in current column ; Swap the row with non - zero element with this row . ; If we did not find any row with non - zero element in current columnm , then all values in this column are 0. ; Reduce number of columns ; Copy the last column here ; Process this row again ; Uncomment these lines to see intermediate results display ( mat , R , C ) ; printf ( " \n " ) ; ; Function to display a matrix ; Driver code"
Solution in C#:

 using System ; class GFG { static int R = 3 ; static int C = 3 ; static void swap ( int [ , ] mat , int row1 , int row2 , int col ) { for ( int i = 0 ; i < col ; i ++ ) { int temp = mat [ row1 , i ] ; mat [ row1 , i ] = mat [ row2 , i ] ; mat [ row2 , i ] = temp ; } } static int rankOfMatrix ( int [ , ] mat ) { int rank = C ; for ( int row = 0 ; row < rank ; row ++ ) { if ( mat [ row , row ] != 0 ) { for ( int col = 0 ; col < R ; col ++ ) { if ( col != row ) { double mult = ( double ) mat [ col , row ] / mat [ row , row ] ; for ( int i = 0 ; i < rank ; i ++ ) mat [ col , i ] -= ( int ) mult * mat [ row , i ] ; } } } else { bool reduce = true ; for ( int i = row + 1 ; i < R ; i ++ ) { if ( mat [ i , row ] != 0 ) { swap ( mat , row , i , rank ) ; reduce = false ; break ; } } if ( reduce ) { rank -- ; for ( int i = 0 ; i < R ; i ++ ) mat [ i , row ] = mat [ i , rank ] ; } row -- ; } } return rank ; } static void display ( int [ , ] mat , int row , int col ) { for ( int i = 0 ; i < row ; i ++ ) { for ( int j = 0 ; j < col ; j ++ ) Console . Write ( " ▁ " + mat [ i , j ] ) ; Console . Write ( "
 " ) ; } } public static void Main ( ) { int [ , ] mat = { { 10 , 20 , 10 } , { - 20 , - 30 , 10 } , { 30 , 50 , 0 } } ; Console . Write ( " Rank ▁ of ▁ the ▁ matrix ▁ is ▁ : ▁ " + rankOfMatrix ( mat ) ) ; } }


"Program for Shortest Job First ( SJF ) scheduling | Set 2 ( Preemptive ) | C # program to implement Shortest Remaining Time First Shortest Remaining Time First ( SRTF ) ; public int pid ; Process ID public int bt ; Burst Time public int art ; Arrival Time ; Method to find the waiting time for all processes ; Copy the burst time into rt [ ] ; Process until all processes gets completed ; Find process with minimum remaining time among the processes that arrives till the current time ` ; Reduce remaining time by one ; Update minimum ; If a process gets completely executed ; Increment complete ; Find finish time of current process ; Calculate waiting time ; Increment time ; Method to calculate turn around time ; calculating turnaround time by adding bt [ i ] + wt [ i ] ; Method to calculate average time ; Function to find waiting time of all processes ; Function to find turn around time for all processes ; Display processes along with all details ; Calculate total waiting time and total turnaround time ; Driver Method"
Solution in C#:

using System ; public class Process { public Process ( int pid , int bt , int art ) { this . pid = pid ; this . bt = bt ; this . art = art ; } } public class GFG { static void findWaitingTime ( Process [ ] proc , int n , int [ ] wt ) { int [ ] rt = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) rt [ i ] = proc [ i ] . bt ; int complete = 0 , t = 0 , minm = int . MaxValue ; int shortest = 0 , finish_time ; bool check = false ; while ( complete != n ) { for ( int j = 0 ; j < n ; j ++ ) { if ( ( proc [ j ] . art <= t ) && ( rt [ j ] < minm ) && rt [ j ] > 0 ) { minm = rt [ j ] ; shortest = j ; check = true ; } } if ( check == false ) { t ++ ; continue ; } rt [ shortest ] -- ; minm = rt [ shortest ] ; if ( minm == 0 ) minm = int . MaxValue ; if ( rt [ shortest ] == 0 ) { complete ++ ; check = false ; finish_time = t + 1 ; wt [ shortest ] = finish_time - proc [ shortest ] . bt - proc [ shortest ] . art ; if ( wt [ shortest ] < 0 ) wt [ shortest ] = 0 ; } t ++ ; } } static void findTurnAroundTime ( Process [ ] proc , int n , int [ ] wt , int [ ] tat ) { for ( int i = 0 ; i < n ; i ++ ) tat [ i ] = proc [ i ] . bt + wt [ i ] ; } static void findavgTime ( Process [ ] proc , int n ) { int [ ] wt = new int [ n ] ; int [ ] tat = new int [ n ] ; int total_wt = 0 , total_tat = 0 ; findWaitingTime ( proc , n , wt ) ; findTurnAroundTime ( proc , n , wt , tat ) ; Console . WriteLine ( " Processes ▁ " + " ▁ Burst ▁ time ▁ " + " ▁ Waiting ▁ time ▁ " + " ▁ Turn ▁ around ▁ time " ) ; for ( int i = 0 ; i < n ; i ++ ) { total_wt = total_wt + wt [ i ] ; total_tat = total_tat + tat [ i ] ; Console . WriteLine ( " ▁ " + proc [ i ] . pid + " 	 	 " + proc [ i ] . bt + " 	 	 ▁ " + wt [ i ] + " 	 	 " + tat [ i ] ) ; } Console . WriteLine ( " Average ▁ waiting ▁ time ▁ = ▁ " + ( float ) total_wt / ( float ) n ) ; Console . WriteLine ( " Average ▁ turn ▁ around ▁ time ▁ = ▁ " + ( float ) total_tat / ( float ) n ) ; } public static void Main ( String [ ] args ) { Process [ ] proc = { new Process ( 1 , 6 , 1 ) , new Process ( 2 , 8 , 1 ) ,...


"Program for Surface Area of Octahedron | C # program to calculate surface area of Octahedron . ; utility Function ; Driver code"
Solution in C#:

using System ; class GFG { static double surface_area_octahedron ( double side ) { return ( 2 * ( Math . Sqrt ( 3 ) ) * ( side * side ) ) ; } public static void Main ( ) { double side = 7 ; Console . WriteLine ( " Surface ▁ area ▁ of ▁ octahedron ▁ = " + surface_area_octahedron ( side ) ) ; } }


"Program for Tower of Hanoi | C # recursive program to solve tower of hanoi puzzle ; Driver method ; Number of disks ; A , B and C are names of rods"
Solution in C#:

using System ; class GFG { static void towerOfHanoi ( int n , char from_rod , char to_rod , char aux_rod ) { if ( n == 1 ) { Console . WriteLine ( " Move ▁ disk ▁ 1 ▁ from ▁ rod ▁ " + from_rod + " ▁ to ▁ rod ▁ " + to_rod ) ; return ; } towerOfHanoi ( n - 1 , from_rod , aux_rod , to_rod ) ; Console . WriteLine ( " Move ▁ disk ▁ " + n + " ▁ from ▁ rod ▁ " + from_rod + " ▁ to ▁ rod ▁ " + to_rod ) ; towerOfHanoi ( n - 1 , aux_rod , to_rod , from_rod ) ; } public static void Main ( String [ ] args ) { int n = 4 ; towerOfHanoi ( n , ' A ' , ' C ' , ' B ' ) ; } }


"Program for Volume and Surface Area of Cube | C # program to find area and total surface area of cube ; utility function ; Driver code"
Solution in C#:

using System ; class GFG { static double areaCube ( double a ) { return ( a * a * a ) ; } static double surfaceCube ( double a ) { return ( 6 * a * a ) ; } public static void Main ( ) { double a = 5 ; Console . WriteLine ( " Area ▁ = ▁ " + areaCube ( a ) ) ; Console . WriteLine ( " Total ▁ surface ▁ area ▁ = ▁ " + surfaceCube ( a ) ) ; } }


"Program for Volume and Surface Area of Cuboid | C # program to find volume and total surface area of cuboid ; utility function ; Driver code"
Solution in C#:

using System ; class GFG { static double areaCuboid ( double l , double h , double w ) { return ( l * h * w ) ; } static double surfaceAreaCuboid ( double l , double h , double w ) { return ( 2 * l * w + 2 * w * h + 2 * l * h ) ; } public static void Main ( ) { double l = 1 ; double h = 5 ; double w = 7 ; Console . WriteLine ( " Area ▁ = ▁ " + areaCuboid ( l , h , w ) ) ; Console . WriteLine ( " Total ▁ Surface ▁ Area ▁ = ▁ " + surfaceAreaCuboid ( l , h , w ) ) ; } }


"Program for Volume and Surface area of Frustum of Cone | C # program to calculate Volume and Surface area of frustum of cone ; Function to calculate Volume of frustum of cone ; Function to calculate Curved Surface area of frustum of cone ; Function to calculate Total Surface area of frustum of cone ; Driver function ; Printing value of volume and surface area"
Solution in C#:

using System ; public class demo { static float pi = 3.14159f ; public static float volume ( float r , float R , float h ) { return ( float ) 1 / 3 * pi * h * ( r * r + R * R + r * R ) ; } public static float curved_surface_area ( float r , float R , float l ) { return pi * l * ( R + r ) ; } public static float total_surface_area ( float r , float R , float l , float h ) { return pi * l * ( R + r ) + pi * ( r * r + R * R ) ; } public static void Main ( ) { float small_radius = 3 ; float big_radius = 8 ; float slant_height = 13 ; float height = 12 ; Console . Write ( " Volume ▁ Of ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; Console . WriteLine ( volume ( small_radius , big_radius , height ) ) ; Console . Write ( " Curved ▁ Surface ▁ Area ▁ Of " + " ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; Console . WriteLine ( curved_surface_area ( small_radius , big_radius , slant_height ) ) ; Console . Write ( " Total ▁ Surface ▁ Area ▁ Of " + " ▁ Frustum ▁ of ▁ Cone ▁ : ▁ " ) ; Console . WriteLine ( total_surface_area ( small_radius , big_radius , slant_height , height ) ) ; } }


"Program for Worst Fit algorithm in Memory Management | C # implementation of worst - Fit algorithm ; Method to allocate memory to blocks as per worst fit algorithm ; Stores block id of the block allocated to a process ; Initially no block is assigned to any process ; pick each process and find suitable blocks according to its size ad assign to it ; Find the best fit block for current process ; If we could find a block for current process ; allocate block j to p [ i ] process ; Reduce available memory in this block . ; Driver code"
Solution in C#:

 using System ; class GFG { static void worstFit ( int [ ] blockSize , int m , int [ ] processSize , int n ) { int [ ] allocation = new int [ n ] ; for ( int i = 0 ; i < allocation . Length ; i ++ ) allocation [ i ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int wstIdx = - 1 ; for ( int j = 0 ; j < m ; j ++ ) { if ( blockSize [ j ] >= processSize [ i ] ) { if ( wstIdx == - 1 ) wstIdx = j ; else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ; } } if ( wstIdx != - 1 ) { allocation [ i ] = wstIdx ; blockSize [ wstIdx ] -= processSize [ i ] ; } } Console . WriteLine ( "
 Process ▁ No . 	 Process ▁ Size 	 Block ▁ no . " ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( " ▁ " + ( i + 1 ) + " 	 	 	 " + processSize [ i ] + " 	 	 	 " ) ; if ( allocation [ i ] != - 1 ) Console . Write ( allocation [ i ] + 1 ) ; else Console . Write ( " Not ▁ Allocated " ) ; Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { int [ ] blockSize = { 100 , 500 , 200 , 300 , 600 } ; int [ ] processSize = { 212 , 417 , 112 , 426 } ; int m = blockSize . Length ; int n = processSize . Length ; worstFit ( blockSize , m , processSize , n ) ; } }


"Program for average of an array without running into overflow | C # program for the above approach ; Function to calculate average of an array using standard method ; Stores the sum of array ; Find the sum of the array ; Return the average ; Function to calculate average of an array using efficient method ; Store the average of the array ; Traverse the array arr [ ] ; Update avg ; Return avg ; Driver Code ; Input ; Function call"
Solution in C#:

using System ; class GFG { static double average ( int [ ] arr , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; return ( double ) ( sum / N ) ; } static double mean ( int [ ] arr , int N ) { double avg = 0.0 ; for ( int i = 0 ; i < N ; i ++ ) { avg += ( ( double ) ( ( arr [ i ] - avg ) / ( i + 1 ) ) ) ; } return avg ; } static public void Main ( ) { int [ ] arr = { Int32 . MaxValue , 1 , 2 } ; int N = arr . Length ; Console . WriteLine ( " Average ▁ by ▁ Standard ▁ method : ▁ " + ( average ( arr , N ) ) . ToString ( " F10" ) ) ; Console . WriteLine ( " Average ▁ by ▁ Efficient ▁ method : ▁ " + ( mean ( arr , N ) ) . ToString ( " F10" ) ) ; } }


"Program for centered nonagonal number | C # Program to find nth centered nonagonal number . ; Function to find nth centered nonagonal number . ; Formula to find nth centered nonagonal number . ; Driver function ."
Solution in C#:

using System ; class GFG { static int centeredNonagonal ( int n ) { return ( 3 * n - 2 ) * ( 3 * n - 1 ) / 2 ; } public static void Main ( ) { int n = 10 ; Console . Write ( centeredNonagonal ( n ) ) ; } }


"Program for credit card number validation | C # program to check if a given credit card is valid or not . ; Main Method ; Return true if the card number is valid ; Get the result from Step 2 ; Return this number if it is a single digit , otherwise , return the sum of the two digits ; Return sum of odd - place digits in number ; Return true if the digit d is a prefix for number ; Return the number of digits in d ; Return the first k number of digits from number . If the number of digits in number is less than k , return number ."
Solution in C#:

using System ; class CreditCard { public static void Main ( ) { long number = 5196081888500645L ; Console . Write ( number + " ▁ is ▁ " + ( isValid ( number ) ? " valid " : " invalid " ) ) ; } public static bool isValid ( long number ) { return ( getSize ( number ) >= 13 && getSize ( number ) <= 16 ) && ( prefixMatched ( number , 4 ) || prefixMatched ( number , 5 ) || prefixMatched ( number , 37 ) || prefixMatched ( number , 6 ) ) && ( ( sumOfDoubleEvenPlace ( number ) + sumOfOddPlace ( number ) ) % 10 == 0 ) ; } public static int sumOfDoubleEvenPlace ( long number ) { int sum = 0 ; String num = number + " " ; for ( int i = getSize ( number ) - 2 ; i >= 0 ; i -= 2 ) sum += getDigit ( int . Parse ( num [ i ] + " " ) * 2 ) ; return sum ; } public static int getDigit ( int number ) { if ( number < 9 ) return number ; return number / 10 + number % 10 ; } public static int sumOfOddPlace ( long number ) { int sum = 0 ; String num = number + " " ; for ( int i = getSize ( number ) - 1 ; i >= 0 ; i -= 2 ) sum += int . Parse ( num [ i ] + " " ) ; return sum ; } public static bool prefixMatched ( long number , int d ) { return getPrefix ( number , getSize ( d ) ) == d ; } public static int getSize ( long d ) { String num = d + " " ; return num . Length ; } public static long getPrefix ( long number , int k ) { if ( getSize ( number ) > k ) { String num = number + " " ; return long . Parse ( num . Substring ( 0 , k ) ) ; } return number ; } }


"Program for cube sum of first n natural numbers | Efficient C # program to find sum of cubes of first n natural numbers that avoids overflow if result is going to be withing limits . ; Returns the sum of series ; Driver code"
Solution in C#:

using System ; class GFG { public static int sumOfSeries ( int n ) { int x ; if ( n % 2 == 0 ) x = ( n / 2 ) * ( n + 1 ) ; else x = ( ( n + 1 ) / 2 ) * n ; return x * x ; } static public void Main ( ) { int n = 5 ; Console . WriteLine ( sumOfSeries ( n ) ) ; } }


"Program for decimal to hexadecimal conversion | C # program to convert a decimal number to hexadecimal number ; function to convert decimal to hexadecimal ; char array to store hexadecimal number ; counter for hexadecimal number array ; temporary variable to store remainder ; storing remainder in temp variable . ; check if temp < 10 ; printing hexadecimal number array in reverse order ; Driver Code"
Solution in C#:

using System ; class GFG { static void decToHexa ( int n ) { char [ ] hexaDeciNum = new char [ 100 ] ; int i = 0 ; while ( n != 0 ) { int temp = 0 ; temp = n % 16 ; if ( temp < 10 ) { hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ; i ++ ; } else { hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ; i ++ ; } n = n / 16 ; } for ( int j = i - 1 ; j >= 0 ; j -- ) Console . Write ( hexaDeciNum [ j ] ) ; } public static void Main ( String [ ] args ) { int n = 2545 ; decToHexa ( n ) ; } }


"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 ."
Solution in C#:

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 ] + " ▁ " ) ; } }


"Program for finding the Integral of a given function using Boole 's Rule | C # program to implement Boole 's Rule on the given function ; Function to return the value of f ( x ) for the given value of x ; Function to computes the integrand of y at the given intervals of x with step size h and the initial limit a and final limit b ; Number of intervals ; Computing the step size ; Substituing a = 0 , b = 4 and h = 1 ; Driver code"
Solution in C#:

using System ; class GFG { static float y ( float x ) { return ( 1 / ( 1 + x ) ) ; } static float BooleRule ( float a , float b ) { int n = 4 ; int h ; h = ( int ) ( ( b - a ) / n ) ; float sum = 0 ; float bl = ( 7 * y ( a ) + 32 * y ( a + h ) + 12 * y ( a + 2 * h ) + 32 * y ( a + 3 * h ) + 7 * y ( a + 4 * h ) ) * 2 * h / 45 ; sum = sum + bl ; return sum ; } public static void Main ( string [ ] args ) { Console . Write ( ( " f ( x ) ▁ = ▁ " + System . Math . Round ( BooleRule ( 0 , 4 ) , 4 ) ) ) ; } }


"Program for focal length of a lens | C # program to determine the focal length of a lens ; Function to determine the focal length of a lens ; Driver code ; variable to store the distance between the lens and the image ; variable to store the distance between the lens and the object"
Solution in C#:

using System ; class GFG { static float focal_length ( float image_distance , float object_distance ) { return 1 / ( ( 1 / image_distance ) + ( 1 / object_distance ) ) ; } public static void Main ( ) { float image_distance = 2 ; float object_distance = 50 ; Console . WriteLine ( " Focal ▁ length ▁ of ▁ a ▁ lens ▁ is ▁ " + focal_length ( image_distance , object_distance ) + " ▁ units . " ) ; } }


"Program for harmonic mean of numbers | C # program to find harmonic mean . ; Function that returns harmonic mean . ; Driver code"
Solution in C#:

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 ) ) ; } }


"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"
Solution in C#:

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 length of a string using recursion | C # program to calculate length of a string using recursion ; Function to calculate length ; if we reach at the end of the string ; Driver program to test above function"
Solution in C#:

using System ; public class GFG { private static int recLen ( string str ) { if ( str . Equals ( " " ) ) return 0 ; else return recLen ( str . Substring ( 1 ) ) + 1 ; } public static void Main ( ) { string str = " GeeksforGeeks " ; Console . WriteLine ( recLen ( str ) ) ; } }


"Program for length of the longest word in a sentence | C # program to find the number of charters in the longest word in the sentence . ; Driver code"
Solution in C#:

using System ; class GFG { static int LongestWordLength ( string str ) { String [ ] words = str . Split ( ' ▁ ' ) ; int length = 0 ; for ( int i = 0 ; i < words . Length ; i ++ ) { if ( length < words [ i ] . Length ) { length = words [ i ] . Length ; } } return length ; } static void Main ( ) { string str = " I ▁ am ▁ an ▁ intern ▁ at ▁ geeksforgeeks " ; Console . Write ( LongestWordLength ( str ) ) ; } }


"Program for n 'th node from the end of a Linked List |"
Solution in C#:

static void printNthFromLast ( Node head , int n ) { static int i = 0 ; if ( head == null ) return ; printNthFromLast ( head . next , n ) ; if ( ++ i == n ) Console . Write ( head . data ) ; }


"Program for n | C # program to find the nth EVEN number ; Function to find the nth odd number ; Driver code"
Solution in C#:

using System ; class GFG { static int nthEven ( int n ) { return ( 2 * n ) ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( nthEven ( n ) ) ; } }


"Program for n | C # program to find the nth odd number ; Function to find the nth odd number ; Driver code"
Solution in C#:

using System ; class GFG { static int nthOdd ( int n ) { return ( 2 * n - 1 ) ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( nthOdd ( n ) ) ; } }


"Program for nth Catalan Number |  ; Function to print the number ; For the first number C ( 0 ) ; Iterate till N ; Calculate the number and print it ; Driver code ; Function call"
Solution in C#:

using System ; public class GFG { static void catalan ( int n ) { int cat_ = 1 ; Console . Write ( cat_ + " ▁ " ) ; for ( int i = 1 ; i < n ; i ++ ) { cat_ *= ( 4 * i - 2 ) ; cat_ /= ( i + 1 ) ; Console . Write ( cat_ + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int n = 5 ; catalan ( n ) ; } }


"Program for nth Catalan Number | A dynamic programming based function to find nth Catalan number ; Table to store results of subproblems ; Initialize first two values in table ; Fill entries in catalan [ ] using recursive formula ; Return last entry ; Driver code"
Solution in C#:

using System ; class GFG { static uint catalanDP ( uint n ) { uint [ ] catalan = new uint [ n + 2 ] ; catalan [ 0 ] = catalan [ 1 ] = 1 ; for ( uint i = 2 ; i <= n ; i ++ ) { catalan [ i ] = 0 ; for ( uint j = 0 ; j < i ; j ++ ) catalan [ i ] += catalan [ j ] * catalan [ i - j - 1 ] ; } return catalan [ n ] ; } static void Main ( ) { for ( uint i = 0 ; i < 10 ; i ++ ) Console . Write ( catalanDP ( i ) + " ▁ " ) ; } }


"Program for nth Catalan Number | A recursive C # program to find nth catalan number ; A recursive function to find nth catalan number ; Base case ; catalan ( n ) is sum of catalan ( i ) * catalan ( n - i - 1 ) ; Driver Code"
Solution in C#:

using System ; class GFG { static int catalan ( int n ) { if ( n <= 1 ) { return 1 ; } int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { res += catalan ( i ) * catalan ( n - i - 1 ) ; } return res ; } public static void Main ( ) { for ( int i = 0 ; i < 10 ; i ++ ) Console . Write ( catalan ( i ) + " ▁ " ) ; } }


"Program for nth Catalan Number | C # program for nth Catalan Number ; Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; A Binomial coefficient based function to find nth catalan number in O ( n ) time ; Calculate value of 2 nCn ; return 2 nCn / ( n + 1 ) ; Driver code"
Solution in C#:

using System ; class GFG { static long binomialCoeff ( int n , int k ) { long res = 1 ; if ( k > n - k ) { k = n - k ; } for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static long catalan ( int n ) { long c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } public static void Main ( ) { for ( int i = 0 ; i < 10 ; i ++ ) { Console . Write ( catalan ( i ) + " ▁ " ) ; } } }


"Program for nth Fuss – Catalan Number | C # program for nth Fuss - Catalan Number ; Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; A Binomial coefficient based function to find nth Fuss - Catalan number in O ( n ) time ; Calculate value of 3 nCn ; return 3 nCn / ( 2 n + 1 ) ; Driver code"
Solution in C#:

using System ; class GFG { static int binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static int Fuss_catalan ( int n ) { int c = binomialCoeff ( 3 * n , n ) ; return c / ( 2 * n + 1 ) ; } public static void Main ( String [ ] args ) { for ( int i = 0 ; i < 10 ; i ++ ) Console . Write ( Fuss_catalan ( i ) + " ▁ " ) ; } }


"Program for quotient and remainder of big number | C # program to find quotient and remainder when a number is divided by large number represented as String . ; Function to calculate the modulus ; Store the modulus of big number ; Do step by step division ; Update modulo by concatenating current digit . ; Update quotient ; Update mod for next iteration . ; Flag used to remove starting zeros ; Driver Code"
Solution in C#:

 using System ; using System . Collections . Generic ; class GFG { static void modBigNumber ( string num , long m ) { List < int > vec = new List < int > ( ) ; long mod = 0 ; for ( int i = 0 ; i < num . Length ; i ++ ) { int digit = num [ i ] - '0' ; mod = mod * 10 + digit ; int quo = ( int ) ( mod / m ) ; vec . Add ( quo ) ; mod = mod % m ; } Console . Write ( " Remainder ▁ : ▁ " + mod + "
 " ) ; Console . Write ( " Quotient ▁ : ▁ " ) ; bool zeroflag = false ; for ( int i = 0 ; i < vec . Count ; i ++ ) { if ( vec [ i ] == 0 && zeroflag == false ) { continue ; } zeroflag = true ; Console . Write ( vec [ i ] ) ; } return ; } public static void Main ( ) { string num = "14598499948265358486" ; long m = 487 ; modBigNumber ( num , m ) ; } }


"Program for sum of arithmetic series | C # Program to find the sum of arithmetic series . ; Function to find sum of series . ; Driver function"
Solution in C#:

using System ; class GFG { static float sumOfAP ( float a , float d , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + a ; a = a + d ; } return sum ; } public static void Main ( ) { int n = 20 ; float a = 2.5f , d = 1.5f ; Console . Write ( sumOfAP ( a , d , n ) ) ; } }


"Program for sum of arithmetic series | C # efficient solution to find sum of arithmetic series . ; Driver code"
Solution in C#:

using System ; class GFG { static float sumOfAP ( float a , float d , float n ) { float sum = ( n / 2 ) * ( 2 * a + ( n - 1 ) * d ) ; return sum ; } static public void Main ( ) { float n = 20 ; float a = 2.5f , d = 1.5f ; Console . WriteLine ( sumOfAP ( a , d , n ) ) ; } }


"Program for sum of cos ( x ) series | C # program to find the sum of cos ( x ) series ; here x is in degree . we have to convert it to radian for using it with series formula , as in series expansion angle is in radian ; Driver Code"
Solution in C#:

using System ; class GFG { static double PI = 3.142 ; static double cosXSertiesSum ( double x , int n ) { x = x * ( PI / 180.0 ) ; double res = 1 ; double sign = 1 , fact = 1 , pow = 1 ; for ( int i = 1 ; i < 5 ; i ++ ) { sign = sign * - 1 ; fact = fact * ( 2 * i - 1 ) * ( 2 * i ) ; pow = pow * x * x ; res = res + sign * pow / fact ; } return res ; } public static void Main ( ) { float x = 50 ; int n = 5 ; Console . Write ( ( float ) ( cosXSertiesSum ( x , n ) * 1000000 ) / 1000000.00 ) ; } }


"Program for sum of cosh ( x ) series upto Nth term | C # program for the sum of cosh ( x ) series ; function to return the factorial of a number ; function to return the sum of the series ; Driver code"
Solution in C#:

using System ; class GFG { static int fact ( int n ) { int i = 1 , fac = 1 ; for ( i = 1 ; i <= n ; i ++ ) fac = fac * i ; return fac ; } static double log_Expansion ( double x , int n ) { double sum = 0 ; int i = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum = sum + Math . Pow ( x , 2 * i ) / fact ( 2 * i ) ; } return sum ; } public static void Main ( String [ ] args ) { double x = 1 ; int n = 10 ; Console . WriteLine ( log_Expansion ( x , n ) ) ; } }


"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 ."
Solution in C#:

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 for weighted mean of natural numbers . | Program to find weighted mean of first n natural numbers using formula . ; Returns weighted mean assuming for numbers { 1 , 2 , . . n } and weights { 1 , 2 , . . n } ; Driver program to test the function ."
Solution in C#:

using System ; public class GFG { static int weightedMean ( int n ) { return ( 2 * n + 1 ) / 3 ; } static public void Main ( ) { int n = 10 ; Console . WriteLine ( weightedMean ( n ) ) ; } }


"Program to Calculate e ^ x by Recursion ( using Taylor Series ) | C # implementation of the approach ; Recursive Function with static variables p and f ; Termination condition ; Recursive call ; Update the power of x ; Factorial ; Driver code"
Solution in C#:

using System ; class GFG { static double p = 1 , f = 1 ; static double e ( int x , int n ) { double r ; if ( n == 0 ) return 1 ; r = e ( x , n - 1 ) ; p = p * x ; f = f * n ; return ( r + p / f ) ; } static void Main ( ) { int x = 4 , n = 15 ; Console . WriteLine ( Math . Round ( e ( x , n ) , 6 ) ) ; } }


"Program to Calculate the Perimeter of a Decagon | C # program to Calculate the Perimeter of a Decagon ; Function for finding the perimeter ; Driver code"
Solution in C#:

using System ; class GFG { static void CalPeri ( ) { int S = 5 , Perimeter ; Perimeter = 10 * S ; Console . WriteLine ( " The ▁ Perimeter ▁ of ▁ " + " Decagon ▁ is ▁ : ▁ " + Perimeter ) ; } public static void Main ( ) { CalPeri ( ) ; } }


"Program to Change RGB color model to HSV color model | C # program change RGB Color Model to HSV Color Model ; R , G , B values are divided by 255 to change the range from 0. .255 to 0. .1 ; h , s , v = hue , saturation , value double cmax = Math . Max ( r , Math . Max ( g , b ) ) ; maximum of r , g , b double cmin = Math . Min ( r , Math . Min ( g , b ) ) ; minimum of r , g , b double diff = cmax - cmin ; diff of cmax and cmin . ; if cmax and cmax are equal then h = 0 ; if cmax equal r then compute h ; if cmax equal g then compute h ; if cmax equal b then compute h ; if cmax equal zero ; compute v ; Driver Code ; rgb_to_hsv ( 45 , 215 , 0 ) ; rgb_to_hsv ( 31 , 52 , 29 ) ;"
Solution in C#:

using System ; class GFG { static void rgb_to_hsv ( double r , double g , double b ) { r = r / 255.0 ; g = g / 255.0 ; b = b / 255.0 ; double h = - 1 , s = - 1 ; if ( cmax == cmin ) h = 0 ; else if ( cmax == r ) h = ( 60 * ( ( g - b ) / diff ) + 360 ) % 360 ; else if ( cmax == g ) h = ( 60 * ( ( b - r ) / diff ) + 120 ) % 360 ; else if ( cmax == b ) h = ( 60 * ( ( r - g ) / diff ) + 240 ) % 360 ; if ( cmax == 0 ) s = 0 ; else s = ( diff / cmax ) * 100 ; double v = cmax * 100 ; Console . WriteLine ( " ( " + h + " ▁ " + s + " ▁ " + v + " ) " ) ; } public static void Main ( String [ ] args ) { rgb_to_hsv ( 129 , 88 , 47 ) ; } }


"Program to Convert BCD number into Decimal number | C # code to convert BCD to its decimal number ( base 10 ) . Including Header Files ; Function to convert BCD to Decimal ; Iterating through the bits backwards ; Forming the equivalent digit ( 0 to 9 ) from the group of 4. ; Reinitialize all variables and compute the number . ; Update the answer ; Reverse the number formed . ; Driver code ; Function Call"
Solution in C#:

using System ; class GFG { public static int bcdToDecimal ( String s ) { int len = s . Length ; int check = 0 , check0 = 0 ; int num = 0 , sum = 0 ; int mul = 1 , rev = 0 ; for ( int i = len - 1 ; i >= 0 ; i -- ) { sum += ( s [ i ] - '0' ) * mul ; mul *= 2 ; check ++ ; if ( check == 4 i == 0 ) { if ( sum == 0 && check0 == 0 ) { num = 1 ; check0 = 1 ; } else { num = num * 10 + sum ; } check = 0 ; sum = 0 ; mul = 1 ; } } while ( num > 0 ) { rev = rev * 10 + ( num % 10 ) ; num /= 10 ; } if ( check0 == 1 ) return rev - 1 ; return rev ; } public static void Main ( String [ ] args ) { String s = "100000101000" ; Console . WriteLine ( bcdToDecimal ( s ) ) ; } }


"Program to Convert Hexadecimal Number to Binary | C # program to convert Hexadecimal number to Binary ; function to convert Hexadecimal to Binary Number ; Driver code ; Get the Hexadecimal number ; Convert HexaDecimal to Binary"
Solution in C#:

 class GFG { static void HexToBin ( char [ ] hexdec ) { int i = 0 ; while ( hexdec [ i ] != ' \u0000' ) { switch ( hexdec [ i ] ) { case '0' : System . Console . Write ( "0000" ) ; break ; case '1' : System . Console . Write ( "0001" ) ; break ; case '2' : System . Console . Write ( "0010" ) ; break ; case '3' : System . Console . Write ( "0011" ) ; break ; case '4' : System . Console . Write ( "0100" ) ; break ; case '5' : System . Console . Write ( "0101" ) ; break ; case '6' : System . Console . Write ( "0110" ) ; break ; case '7' : System . Console . Write ( "0111" ) ; break ; case '8' : System . Console . Write ( "1000" ) ; break ; case '9' : System . Console . Write ( "1001" ) ; break ; case ' A ' : case ' a ' : System . Console . Write ( "1010" ) ; break ; case ' B ' : case ' b ' : System . Console . Write ( "1011" ) ; break ; case ' C ' : case ' c ' : System . Console . Write ( "1100" ) ; break ; case ' D ' : case ' d ' : System . Console . Write ( "1101" ) ; break ; case ' E ' : case ' e ' : System . Console . Write ( "1110" ) ; break ; case ' F ' : case ' f ' : System . Console . Write ( "1111" ) ; break ; default : System . Console . Write ( "
 Invalid ▁ hexadecimal ▁ digit ▁ " + hexdec [ i ] ) ; break ; } i ++ ; } } static void Main ( ) { string s = "1AC5" ; char [ ] hexdec = new char [ 100 ] ; hexdec = s . ToCharArray ( ) ; System . Console . Write ( " Equivalent ▁ Binary ▁ value ▁ is ▁ : ▁ " ) ; try { HexToBin ( hexdec ) ; } catch ( System . IndexOutOfRangeException ) { System . Console . Write ( " " ) ; } } }


"Program to Convert Km / hr to miles / hr and vice versa | C # program for the conversion kmph to mph and vice versa ; Function to convert kmph to mph ; Function to convert mph to kmph ; Driver code to check the above function"
Solution in C#:

using System ; class GFG { static double kmphTOmph ( double kmph ) { return 0.6214 * kmph ; } static double mphTOkmph ( double mph ) { return mph * 1.60934 ; } public static void Main ( ) { double kmph = 150 ; double mph = 100 ; Console . WriteLine ( " speed ▁ in ▁ miles / hr ▁ is ▁ " + kmphTOmph ( kmph ) ) ; Console . WriteLine ( " speed ▁ in ▁ km / hr ▁ is ▁ " + mphTOkmph ( mph ) ) ; } }


"Program to Encrypt a String using ! and @ | C # program to Encrypt the String using ! and @ ; Function to encrypt the string ; evenPos is for storing encrypting char at evenPosition oddPos is for storing encrypting char at oddPosition ; Get the number of times the character is to be repeated ; if i is odd , print ' ! ' else print ' @ ' ; Driver code ; Encrypt the String"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void encrypt ( char [ ] input ) { char evenPos = ' @ ' , oddPos = ' ! ' ; int repeat , ascii ; for ( int i = 0 ; i < input . Length ; i ++ ) { ascii = input [ i ] ; repeat = ascii >= 97 ? ascii - 96 : ascii - 64 ; for ( int j = 0 ; j < repeat ; j ++ ) { if ( i % 2 == 0 ) Console . Write ( " { 0 } " , oddPos ) ; else Console . Write ( " { 0 } " , evenPos ) ; } } } public static void Main ( String [ ] args ) { char [ ] input = { ' A ' , ' b ' , ' C ' , ' d ' } ; encrypt ( input ) ; } }


"Program to Find the value of cos ( nÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬¦½ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬¹ ÃƒÆ ’ Ã ¢ â ‚¬¦ Ãƒ ¢ Ã ¢ â € š ¬ Ã … â € œ ) | C # program to find the value of cos ( n - theta ) ; Function to calculate the binomial coefficient upto 15 ; use simple DP to find coefficient ; Function to find the value of cos ( n - theta ) ; find sinTheta from cosTheta ; to store required answer ; use to toggle sign in sequence . ; Driver code"
Solution in C#:

using System ; public class GFG { static int MAX = 16 ; static int [ , ] nCr = new int [ MAX , MAX ] ; static void binomial ( ) { for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { if ( j == 0 j == i ) nCr [ i , j ] = 1 ; else nCr [ i , j ] = nCr [ i - 1 , j ] + nCr [ i - 1 , j - 1 ] ; } } } static double findCosnTheta ( double cosTheta , int n ) { double sinTheta = Math . Sqrt ( 1 - cosTheta * cosTheta ) ; double ans = 0 ; int toggle = 1 ; for ( int i = 0 ; i <= n ; i += 2 ) { ans = ans + nCr [ n , i ] * Math . Pow ( cosTheta , n - i ) * Math . Pow ( sinTheta , i ) * toggle ; toggle = toggle * - 1 ; } return ans ; } public static void Main ( ) { binomial ( ) ; double cosTheta = 0.5 ; int n = 10 ; Console . WriteLine ( findCosnTheta ( cosTheta , n ) ) ; } }


"Program to Interchange Diagonals of Matrix | C # program to interchange the diagonals of matrix ; Function to interchange diagonals ; swap elements of diagonal ; Driver Code"
Solution in C#:

using System ; class GFG { public static int N = 3 ; static void interchangeDiagonals ( int [ , ] array ) { for ( int i = 0 ; i < N ; ++ i ) if ( i != N / 2 ) { int temp = array [ i , i ] ; array [ i , i ] = array [ i , N - i - 1 ] ; array [ i , N - i - 1 ] = temp ; } for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) Console . Write ( array [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int [ , ] array = { { 4 , 5 , 6 } , { 1 , 2 , 3 } , { 7 , 8 , 9 } } ; interchangeDiagonals ( array ) ; } }


"Program to accept String starting with Capital letter | C # program to accept String starting with Capital letter ; Function to check if first character is Capital ; Function to check ; Driver function"
Solution in C#:

using System ; class GFG { static int checkIfStartsWithCapital ( string str ) { if ( str [ 0 ] >= ' A ' && str [ 0 ] <= ' Z ' ) return 1 ; else return 0 ; } static void check ( string str ) { if ( checkIfStartsWithCapital ( str ) == 1 ) Console . WriteLine ( " Accepted " ) ; else Console . WriteLine ( " Not ▁ Accepted " ) ; } public static void Main ( ) { string str = " GeeksforGeeks " ; check ( str ) ; str = " geeksforgeeks " ; check ( str ) ; } }


"Program to accept Strings starting with a Vowel | C # program to accept String starting with Vowel ; Function to check if first character is vowel ; Function to check ; Driver code"
Solution in C#:

 using System ; class GFG { static int checkIfStartsWithVowels ( char [ ] str ) { if ( ! ( str [ 0 ] == ' A ' str [ 0 ] == ' a ' str [ 0 ] == ' E ' str [ 0 ] == ' e ' str [ 0 ] == ' I ' str [ 0 ] == ' i ' str [ 0 ] == ' O ' str [ 0 ] == ' o ' str [ 0 ] == ' U ' str [ 0 ] == ' u ' ) ) return 1 ; else return 0 ; } static void check ( String str ) { if ( checkIfStartsWithVowels ( str . ToCharArray ( ) ) == 1 ) Console . Write ( " Not ▁ Accepted
 " ) ; else Console . Write ( " Accepted
 " ) ; } public static void Main ( String [ ] args ) { String str = " animal " ; check ( str ) ; str = " zebra " ; check ( str ) ; } }


"Program to accept a Strings which contains all the Vowels | C # implementation to check that a String contains all vowels ; Function to to check that a String contains all vowels ; Hash Array of size 5 such that the index 0 , 1 , 2 , 3 and 4 represent the vowels a , e , i , o and u ; Loop the String to mark the vowels which are present ; Loop to check if there is any vowel which is not present in the String ; Function to to check that a String contains all vowels ; Driver Code"
Solution in C#:

 using System ; class GFG { static int checkIfAllVowels ( String str ) { int [ ] hash = new int [ 5 ] ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == ' A ' str [ i ] == ' a ' ) hash [ 0 ] = 1 ; else if ( str [ i ] == ' E ' str [ i ] == ' e ' ) hash [ 1 ] = 1 ; else if ( str [ i ] == ' I ' str [ i ] == ' i ' ) hash [ 2 ] = 1 ; else if ( str [ i ] == ' O ' str [ i ] == ' o ' ) hash [ 3 ] = 1 ; else if ( str [ i ] == ' U ' str [ i ] == ' u ' ) hash [ 4 ] = 1 ; } for ( int i = 0 ; i < 5 ; i ++ ) { if ( hash [ i ] == 0 ) { return 1 ; } } return 0 ; } static void checkIfAllVowelsArePresent ( String str ) { if ( checkIfAllVowels ( str ) == 1 ) Console . Write ( " Not ▁ Accepted
 " ) ; else Console . Write ( " Accepted
 " ) ; } public static void Main ( String [ ] args ) { String str = " aeioubc " ; checkIfAllVowelsArePresent ( str ) ; } }


"Program to add two fractions | C # program to add 2 fractions ; Function to return gcd of a and b ; Function to convert the obtained fraction into it 's simplest form ; Finding gcd of both terms ; Converting both terms into simpler terms by dividing them by common factor ; Function to add two fractions ; Finding gcd of den1 and den2 ; Denominator of final fraction obtained finding LCM of den1 and den2 LCM * GCD = a * b ; Changing the fractions to have same denominator Numerator of the final fraction obtained ; Calling function to convert final fraction into it 's simplest form ; Driver program"
Solution in C#:

class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static void lowest ( int den3 , int num3 ) { int common_factor = gcd ( num3 , den3 ) ; den3 = den3 / common_factor ; num3 = num3 / common_factor ; System . Console . WriteLine ( num3 + " / " + den3 ) ; } static void addFraction ( int num1 , int den1 , int num2 , int den2 ) { int den3 = gcd ( den1 , den2 ) ; den3 = ( den1 * den2 ) / den3 ; int num3 = ( num1 ) * ( den3 / den1 ) + ( num2 ) * ( den3 / den2 ) ; lowest ( den3 , num3 ) ; } public static void Main ( ) { int num1 = 1 , den1 = 500 , num2 = 2 , den2 = 1500 ; System . Console . Write ( num1 + " / " + den1 + " ▁ + ▁ " + num2 + " / " + den2 + " ▁ is ▁ equal ▁ to ▁ " ) ; addFraction ( num1 , den1 , num2 , den2 ) ; } }


"Program to add two integers of given base | C # implementation to find the sum of two integers of base B ; Function to find the sum of two integers of base B ; Padding 0 in front of the number to make both numbers equal ; Condition to check if the strings have lengths mis - match ; Loop to find the find the sum of two integers of base B ; Current Place value for the resultant sum ; Update carry ; Find current digit ; Update sum result ; Driver Code ; Function Call"
Solution in C#:

using System ; class GFG { static string sumBaseB ( string a , string b , int base_var ) { int len_a , len_b ; len_a = a . Length ; len_b = b . Length ; string sum , s ; s = " " ; sum = " " ; int diff ; diff = Math . Abs ( len_a - len_b ) ; for ( int i = 1 ; i <= diff ; i ++ ) s += "0" ; if ( len_a < len_b ) a = s + a ; else b = s + b ; int curr , carry = 0 ; for ( int i = Math . Max ( len_a , len_b ) - 1 ; i > - 1 ; i -- ) { curr = carry + ( a [ i ] - '0' ) + ( b [ i ] - '0' ) ; carry = curr / base_var ; curr = curr % base_var ; sum = ( char ) ( curr + '0' ) + sum ; } if ( carry > 0 ) sum = ( char ) ( carry + '0' ) + sum ; return sum ; } public static void Main ( string [ ] args ) { string a , b , sum ; int base_var ; a = "123" ; b = "234" ; base_var = 6 ; sum = sumBaseB ( a , b , base_var ) ; Console . WriteLine ( sum ) ; } }


"Program to balance the given Chemical Equation | C # program to balance the given Chemical Equation ; Function to calculate GCD ; Function to calculate b1 , b2 and b3 ; Variable declaration ; temp variable to store gcd ; Computing GCD ; Driver code"
Solution in C#:

 using System ; public class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void balance ( int x , int y , int p , int q ) { int b1 , b2 , b3 ; if ( p % x == 0 && q % y == 0 ) { b1 = p / x ; b2 = q / y ; b3 = 1 ; } else { p = p * y ; q = q * x ; b3 = x * y ; int temp = gcd ( p , gcd ( q , b3 ) ) ; b1 = p / temp ; b2 = q / temp ; b3 = b3 / temp ; } Console . Write ( b1 + " ▁ " + b2 + " ▁ " + b3 + "
 " ) ; } public static void Main ( String [ ] args ) { int x = 2 , y = 3 , p = 4 , q = 5 ; balance ( x , y , p , q ) ; } }


"Program to build a DFA that checks if a string ends with "01" or "10" | C # Program to DFA that accepts string ending with 01 or 10. ; End position is checked using the string length value . q0 is the starting state . q1 and q2 are intermediate states . q3 and q4 are final states . ; state transitions 0 takes to q1 , 1 takes to q3 ; state transitions 0 takes to q4 , 1 takes to q2 ; state transitions 0 takes to q4 , 1 takes to q2 ; state transitions 0 takes to q1 , 1 takes to q3 ; state transitions 0 takes to q1 , 1 takes to q2 ; Driver Code ; all state transitions are printed . if string is accpetable , YES is printed . else NO is printed"
Solution in C#:

using System ; class GFG { static void q1 ( string s , int i ) { Console . Write ( " q1 - > " ) ; if ( i == s . Length ) { Console . WriteLine ( " NO " ) ; return ; } if ( s [ i ] == '0' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q2 ( string s , int i ) { Console . Write ( " q2 - > " ) ; if ( i == s . Length ) { Console . WriteLine ( " NO ▁ " ) ; return ; } if ( s [ i ] == '0' ) q4 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q3 ( string s , int i ) { Console . Write ( " q3 - > " ) ; if ( i == s . Length ) { Console . WriteLine ( " YES " ) ; return ; } if ( s [ i ] == '0' ) q4 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q4 ( string s , int i ) { Console . Write ( " q4 - > " ) ; if ( i == s . Length ) { Console . WriteLine ( " YES " ) ; return ; } if ( s [ i ] == '0' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q0 ( string s , int i ) { Console . Write ( " q0 - > " ) ; if ( i == s . Length ) { Console . WriteLine ( " NO " ) ; return ; } if ( s [ i ] == '0' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } public static void Main ( ) { string s = "010101" ; Console . Write ( " State ▁ transitions ▁ are ▁ " ) ; q0 ( s , 0 ) ; } }


"Program to build a DFA to accept strings that start and end with same character | C # Program for DFA that accepts string if it starts and ends with same character ; Function for the state Q1 ; Condition to check end of string ; State transitions ' a ' takes to q1 , and ' b ' takes to q2 ; Function for the state Q2 ; Condition to check end of string ; State transitions ' a ' takes to q1 , and ' b ' takes to q2 ; Function for the state Q3 ; Condition to check end of string ; State transitions ' a ' takes to q4 , and ' b ' takes to q3 ; Function for the state Q4 ; Condition to check end of string ; State transitions ' a ' takes to q4 , and ' b ' takes to q3 ; Function for the state Q0 ; Condition to check end of string ; State transitions ' a ' takes to q1 , and ' b ' takes to q3 ; Driver Code ; Since q0 is the starting state Send the string to q0"
Solution in C#:

using System ; class GFG { static void q1 ( string s , int i ) { if ( i == s . Length ) { Console . WriteLine ( " Yes " ) ; return ; } if ( s [ i ] == ' a ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q2 ( string s , int i ) { if ( i == s . Length ) { Console . WriteLine ( " No " ) ; return ; } if ( s [ i ] == ' a ' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q3 ( string s , int i ) { if ( i == s . Length ) { Console . WriteLine ( " Yes " ) ; return ; } if ( s [ i ] == ' a ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q4 ( string s , int i ) { if ( i == s . Length ) { Console . WriteLine ( " No " ) ; return ; } if ( s [ i ] == ' a ' ) q4 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q0 ( string s , int i ) { if ( i == s . Length ) { Console . WriteLine ( " No " ) ; return ; } if ( s [ i ] == ' a ' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } public static void Main ( ) { string s = " abbaabb " ; q0 ( s , 0 ) ; } }


"Program to calculate Area Of Octagon | C # Program to find area of Octagon . ; utility function ; Driver code"
Solution in C#:

using System ; class GFG { static double areaOctagon ( double side ) { return ( float ) ( 2 * ( 1 + Math . Sqrt ( 2 ) ) * side * side ) ; } public static void Main ( ) { double side = 4 ; Console . WriteLine ( " Area ▁ of ▁ Regular ▁ Octagon ▁ = ▁ " + areaOctagon ( side ) ) ; } }


"Program to calculate Electricity Bill | C # implementation to calculate the electricity bill ; Function to calculate the electricity bill ; Condition to find the charges bar in which the units consumed is fall ; Driver Code"
Solution in C#:

using System ; class ComputeElectricityBill { public static int calculateBill ( int units ) { if ( units <= 100 ) { return units * 10 ; } else if ( units <= 200 ) { return ( 100 * 10 ) + ( units - 100 ) * 15 ; } else if ( units <= 300 ) { return ( 100 * 10 ) + ( 100 * 15 ) + ( units - 200 ) * 20 ; } else if ( units > 300 ) { return ( 100 * 10 ) + ( 100 * 15 ) + ( 100 * 20 ) + ( units - 300 ) * 25 ; } return 0 ; } public static void Main ( String [ ] args ) { int units = 250 ; Console . WriteLine ( calculateBill ( units ) ) ; } }


"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"
Solution in C#:

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 ) + " % " ) ; } }


"Program to calculate Kinetic Energy and Potential Energy | C # program to implement the above approach ; / Function to calculate Kinetic Energy ; Stores the Kinetic Energy ; Function to calculate Potential Energy ; Stores the Potential Energy ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static double kineticEnergy ( double M , double V ) { double KineticEnergy ; KineticEnergy = 0.5 * M * V * V ; return KineticEnergy ; } static double potentialEnergy ( double M , double H ) { double PotentialEnergy ; PotentialEnergy = M * 9.8 * H ; return PotentialEnergy ; } public static void Main ( ) { double M = 5.5 , H = 23.5 , V = 10.5 ; Console . WriteLine ( " Kinetic ▁ Energy ▁ = ▁ " + kineticEnergy ( M , V ) ) ; Console . Write ( " Potential ▁ Energy ▁ = ▁ " + potentialEnergy ( M , H ) ) ; } }


"Program to calculate Percentile of a student based on rank | C # program to calculate Percentile of a student based on rank ; Program to calculate the percentile ; flat variable to store the result ; calculate and return the percentile ; Driver Code"
Solution in C#:

using System ; class GFG { static float getPercentile ( int rank , int students ) { float result = ( float ) ( students - rank ) / students * 100 ; return result ; } public static void Main ( String [ ] args ) { int your_rank = 805 ; int total_students = 97481 ; Console . Write ( getPercentile ( your_rank , total_students ) ) ; } }


"Program to calculate Profit Or Loss | C # code to demonstrate Profit and Loss ; Function to calculate Profit ; Function to calculate Loss ; Driver Code"
Solution in C#:

using System ; class GFG { static int Profit ( int costPrice , int sellingPrice ) { int profit = ( sellingPrice - costPrice ) ; return profit ; } static int Loss ( int costPrice , int sellingPrice ) { int Loss = ( costPrice - sellingPrice ) ; return Loss ; } public static void Main ( ) { int costPrice = 1500 , sellingPrice = 2000 ; if ( sellingPrice == costPrice ) Console . Write ( " No ▁ profit ▁ nor ▁ Loss " ) ; else if ( sellingPrice > costPrice ) Console . Write ( Profit ( costPrice , sellingPrice ) + " ▁ Profit ▁ " ) ; else Console . Write ( Loss ( costPrice , sellingPrice ) + " ▁ Loss ▁ " ) ; } }


"Program to calculate Root Mean Square | C # program to calculate Root Mean Square ; Function that Calculate Root Mean Square ; Calculate square . ; Calculate Mean . ; Calculate Root . ; Driver Code"
Solution in C#:

using System ; class GFG { static float rmsValue ( int [ ] arr , int n ) { int square = 0 ; float mean = 0 ; float root = 0 ; for ( int i = 0 ; i < n ; i ++ ) { square += ( int ) Math . Pow ( arr [ i ] , 2 ) ; } mean = ( square / ( float ) ( n ) ) ; root = ( float ) Math . Sqrt ( mean ) ; return root ; } public static void Main ( ) { int [ ] arr = { 10 , 4 , 6 , 8 } ; int n = arr . Length ; Console . Write ( rmsValue ( arr , n ) ) ; } }


"Program to calculate Surface Area of Ellipsoid | C # program of the above approach ; Function to find the surface area of the given Ellipsoid ; Formula to find surface area of an Ellipsoid ; Print the area ; Driver Code"
Solution in C#:

using System ; class GFG { static void findArea ( double a , double b , double c ) { double area = 4 * 3.141592653 * Math . Pow ( ( Math . Pow ( a * b , 1.6 ) + Math . Pow ( a * c , 1.6 ) + Math . Pow ( b * c , 1.6 ) ) / 3 , 1 / 1.6 ) ; Console . Write ( Math . Round ( area , 2 ) ) ; } public static void Main ( String [ ] args ) { double A = 11 , B = 12 , C = 13 ; findArea ( A , B , C ) ; } }


"Program to calculate Variance of first N Natural Numbers | C # program to implement the above approach ; Function to calculate Variance of first N natural numbers ; Driver Code"
Solution in C#:

using System ; class GFG { static double find_Variance ( int n ) { long numerator = n * n - 1 ; double ans = ( numerator * 1.0 ) / 12 ; return ans ; } public static void Main ( string [ ] args ) { int N = 5 ; Console . WriteLine ( find_Variance ( N ) ) ; } }


"Program to calculate angle between two N | C # program for the above approach ; Function to find the magnitude of the given vector ; Stores the final magnitude ; Traverse the array ; Return square root of magnitude ; Function to find the dot product of two vectors ; Stores dot product ; Traverse the array ; Return the product ; Stores dot product of two vectors ; Stores magnitude of vector A ; Stores magnitude of vector B ; Stores angle between given vectors ; Print the angle ; Driver Code ; Given magnitude arrays ; Size of the array ; Function call to find the angle between two vectors"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static double magnitude ( double [ ] arr , int N ) { double magnitude = 0 ; for ( int i = 0 ; i < N ; i ++ ) magnitude += arr [ i ] * arr [ i ] ; return Math . Sqrt ( magnitude ) ; } static double dotProduct ( double [ ] arr , double [ ] brr , int N ) { double product = 0 ; for ( int i = 0 ; i < N ; i ++ ) product = product + arr [ i ] * brr [ i ] ; return product ; } static void angleBetweenVectors ( double [ ] arr , double [ ] brr , int N ) { double dotProductOfVectors = dotProduct ( arr , brr , N ) ; double magnitudeOfA = magnitude ( arr , N ) ; double magnitudeOfB = magnitude ( brr , N ) ; double angle = dotProductOfVectors / ( magnitudeOfA * magnitudeOfB ) ; Console . Write ( angle ) ; } public static void Main ( ) { double [ ] arr = { - 0.5 , - 2 , 1 } ; double [ ] brr = { - 1 , - 1 , 0.3 } ; int N = arr . Length ; angleBetweenVectors ( arr , brr , N ) ; } }


"Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given | C # Program to calculate angle on the circumference subtended by the chord when the central angle subtended by the chord is given ; Driver code ; Angle on center"
Solution in C#:

using System ; public class GFG { static float angleOncirCumference ( float z ) { return ( z / 2 ) ; } public static void Main ( String [ ] args ) { float angle = 65 ; float z = angleOncirCumference ( angle ) ; Console . WriteLine ( " The ▁ angle ▁ is ▁ " + z + " ▁ degrees " ) ; } }


"Program to calculate area and perimeter of a rhombus whose diagonals are given | C # program to calculate area and perimeter of a rhombus using diagonals ; calculate area and perimeter of a rhombus ; Driver code"
Solution in C#:

using System ; class GFG { static int rhombusAreaPeri ( int d1 , int d2 ) { int area , perimeter ; area = ( d1 * d2 ) / 2 ; perimeter = ( int ) ( 2 * Math . Sqrt ( Math . Pow ( d1 , 2 ) + Math . Pow ( d2 , 2 ) ) ) ; Console . WriteLine ( " The ▁ area ▁ of ▁ rhombus ▁ with ▁ " + " diagonals ▁ " + d1 + " ▁ and ▁ " + d2 + " ▁ is ▁ " + area + " . " ) ; Console . WriteLine ( " The ▁ perimeter ▁ of ▁ rhombus ▁ " + " with ▁ diagonals ▁ " + d1 + " ▁ and ▁ " + d2 + " ▁ is ▁ " + perimeter + " . " ) ; return 0 ; } public static void Main ( ) { int d1 = 2 , d2 = 4 ; rhombusAreaPeri ( d1 , d2 ) ; } }


"Program to calculate area and perimeter of equilateral triangle | C # Program to find area and perimeter of equilateral triangle ; Function to calculate Area of equilateral triangle ; Function to calculate Perimeter of equilateral triangle ; Driver Code"
Solution in C#:

using System ; class GFG { static float area_equi_triangle ( float side ) { return ( float ) ( ( ( Math . Sqrt ( 3 ) ) / 4 ) * side * side ) ; } static float peri_equi_triangle ( float side ) { return 3 * side ; } public static void Main ( ) { float side = 4 ; Console . Write ( " Area ▁ of ▁ Equilateral ▁ Triangle : " ) ; Console . WriteLine ( area_equi_triangle ( side ) ) ; Console . Write ( " Perimeter ▁ of ▁ Equilateral ▁ Triangle : " ) ; Console . WriteLine ( peri_equi_triangle ( side ) ) ; } }


"Program to calculate area and volume of a Tetrahedron | C # Program to Calculate area of tetrahedron ; Utility Function ; Driver code"
Solution in C#:

using System ; class GFG { public static double area_of_tetrahedron ( int side ) { return ( Math . Sqrt ( 3 ) * ( side * side ) ) ; } static public void Main ( ) { int side = 3 ; Console . WriteLine ( " Area ▁ of ▁ Tetrahedron ▁ = ▁ " + area_of_tetrahedron ( side ) ) ; } }


"Program to calculate area and volume of a Tetrahedron | C # code to find the volume of a tetrahedron ; Function to calculate volume ; Driver Code"
Solution in C#:

using System ; class Tetrahedron { static double vol_tetra ( int side ) { double volume = ( Math . Pow ( side , 3 ) / ( 6 * Math . Sqrt ( 2 ) ) ) ; return volume ; } public static void Main ( ) { int side = 3 ; double vol = vol_tetra ( side ) ; vol = ( double ) Math . Round ( vol * 100 ) / 100 ; Console . WriteLine ( vol ) ; } }


"Program to calculate area of a parallelogram | C # program for the above approach ; Function to return the area of parallelogram using sides and angle at the intersection of diagonal ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using sides and angle at the intersection of sides ; Calculate area of parallelogram ; Return the answer ; Function to return the area of parallelogram using diagonals and angle at the intersection of diagonals ; Calculate area of parallelogram ; Return the answer ; Driver code ; Given diagonal and angle ; Function call ; Print the area"
Solution in C#:

using System ; class GFG { static double Area_Parallelogram1 ( int a , int b , int theta ) { double area = ( Math . Abs ( Math . Tan ( ( theta * Math . PI ) / 180 ) ) / 2 ) * Math . Abs ( a * a - b * b ) ; return area ; } static double Area_Parallelogram2 ( int a , int b , int gamma ) { double area = ( Math . Abs ( Math . Sin ( ( gamma * Math . PI ) / 180 ) ) ) * Math . Abs ( a * b ) ; return area ; } static double Area_Parallelogram3 ( int d1 , int d2 , int theta ) { double area = ( Math . Abs ( Math . Sin ( ( theta * Math . PI ) / 180 ) ) / 2 ) * Math . Abs ( d1 * d2 ) ; return area ; } public static void Main ( String [ ] args ) { int d1 = 3 ; int d2 = 5 ; int theta = 90 ; double area = Area_Parallelogram3 ( d1 , d2 , theta ) ; Console . Write ( " { 0 : F2 } " , area ) ; } }


"Program to calculate area of a rhombus whose one side and diagonal are given | C # program to calculate the area of a rhombus whose one side and one diagonal is given ; function to calculate the area of the rhombus ; Second diagonal ; area of rhombus ; return the area ; Driver code"
Solution in C#:

using System ; class GFG { static double area ( double d1 , double a ) { double d2 = Math . Sqrt ( 4 * ( a * a ) - d1 * d1 ) ; double area = 0.5 * d1 * d2 ; return area ; } public static void Main ( String [ ] args ) { double d = 7.07 ; double a = 5 ; Console . WriteLine ( area ( d , a ) ) ; } }


"Program to calculate area of inner circle which passes through center of outer circle and touches its circumference | C # Implementation of the above approach ; Function calculate the area of the inner circle ; the radius cannot be negative ; area of the circle ; Driver Code"
Solution in C#:

using System ; class GFG { static double innerCirclearea ( double radius ) { if ( radius < 0 ) { return - 1 ; } double r = radius / 2 ; double Area = ( 3.14 * Math . Pow ( r , 2 ) ) ; return Area ; } public static void Main ( String [ ] arr ) { double radius = 4 ; Console . WriteLine ( " Area ▁ of ▁ circle ▁ c2 ▁ = ▁ " + innerCirclearea ( radius ) ) ; } }


"Program to calculate distance between two points in 3 D | C # program to find distance between two points in 3 D . ; Function for distance ; Driver code ; function call for distance"
Solution in C#:

 using System ; class GFG { static void distance ( float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ) { double d = Math . Pow ( ( Math . Pow ( x2 - x1 , 2 ) + Math . Pow ( y2 - y1 , 2 ) + Math . Pow ( z2 - z1 , 2 ) * 1.0 ) , 0.5 ) ; Console . WriteLine ( " Distance ▁ is ▁
 " + d ) ; return ; } public static void Main ( ) { float x1 = 2 ; float y1 = - 5 ; float z1 = 7 ; float x2 = 3 ; float y2 = 4 ; float z2 = 5 ; distance ( x1 , y1 , z1 , x2 , y2 , z2 ) ; } }


"Program to calculate distance between two points | C # code to compute distance ; Function to calculate distance ; Calculating distance ; Driver code"
Solution in C#:

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 ) ; } }


"Program to calculate expected increase in price P after N consecutive days | C # program for the above approach ; Function to find the increased value of P after N days ; Expected value of the number P after N days ; Print the expected value ; Driver code"
Solution in C#:

using System ; class GFG { static void expectedValue ( int P , int a , int b , int N ) { double expValue = P + ( N * 0.5 * ( a + b ) ) ; Console . Write ( expValue ) ; } static void Main ( ) { int P = 3000 , a = 20 , b = 10 , N = 30 ; expectedValue ( P , a , b , N ) ; } }


"Program to calculate gross salary of a person | C # program to implement the above approach ; Function to calculate the salary of the person ; Condition to compute the allowance for the person ; Calculate gross salary ; Driver Code ; Function call"
Solution in C#:

using System ; class GFG { static int computeSalary ( int basic , char grade ) { double allowance ; double hra , da , pf ; hra = 0.2 * basic ; da = 0.5 * basic ; pf = 0.11 * basic ; if ( grade == ' A ' ) { allowance = 1700.0 ; } else if ( grade == ' B ' ) { allowance = 1500.0 ; } else { allowance = 1300.0 ; } double gross ; gross = Math . Round ( basic + hra + da + allowance - pf ) ; return ( int ) gross ; } public static void Main ( String [ ] args ) { int basic = 10000 ; char grade = ' A ' ; Console . WriteLine ( computeSalary ( basic , grade ) ) ; } }


"Program to calculate length of diagonal of a square | C # program for the above approach ; Function to find the length of the diagonal of a square of a given side ; Driver Code"
Solution in C#:

using System ; public class GFG { static double findDiagonal ( double s ) { return ( double ) Math . Sqrt ( 2 ) * s ; } public static void Main ( String [ ] args ) { double S = 10 ; Console . Write ( findDiagonal ( S ) ) ; } }


"Program to calculate sum of an Infinite Arithmetic | C # program for the above approach ; Function to find the sum of the infinite AGP ; Stores the sum of infinite AGP ; Print the required sum ; Driver Code"
Solution in C#:

using System ; class GFG { static void sumOfInfiniteAGP ( double a , double d , double r ) { double ans = a / ( 1 - r ) + ( d * r ) / ( 1 - r * r ) ; Console . Write ( ans ) ; } public static void Main ( ) { double a = 0 , d = 1 , r = 0.5 ; sumOfInfiniteAGP ( a , d , r ) ; } }


"Program to calculate the Area and Perimeter of Incircle of an Equilateral Triangle | C # code to find the area of inscribed circle of equilateral triangle ; function to find the area of inscribed circle ; function to find the perimeter of inscribed circle ; Driver code"
Solution in C#:

 using System ; class GFG { static double PI = 3.14159265 ; public static double area_inscribed ( double a ) { return ( a * a * ( PI / 12 ) ) ; } public static double perm_inscribed ( double a ) { return ( PI * ( a / Math . Sqrt ( 3 ) ) ) ; } public static void Main ( ) { double a = 6.0 ; Console . Write ( " Area ▁ of ▁ inscribed ▁ circle ▁ is ▁ : " + area_inscribed ( a ) ) ; Console . Write ( "
 Perimeter ▁ of ▁ inscribed ▁ circle ▁ is ▁ : " + perm_inscribed ( a ) ) ; } }


"Program to calculate the area between two Concentric Circles | C # program to find area between the two given concentric circles ; Function to find area between the two given concentric circles ; Declare value of pi ; Calculate area of outer circle ; Calculate area of inner circle ; Difference in areas ; Driver code"
Solution in C#:

using System ; class GFG { static double calculateArea ( int x , int y ) { double pi = 3.1415926536 ; double arx = pi * x * x ; double ary = pi * y * y ; return arx - ary ; } public static void Main ( ) { int x = 2 ; int y = 1 ; Console . WriteLine ( calculateArea ( x , y ) ) ; } }


"Program to calculate the area of Kite | C # implementation of the approach ; Function to return the area of kite ; Use above formula ; Driver code"
Solution in C#:

using System ; class GFG { static float areaOfKite ( int d1 , int d2 ) { float area = ( d1 * d2 ) / 2 ; return area ; } public static void Main ( ) { int d1 = 4 , d2 = 6 ; Console . WriteLine ( " Area ▁ of ▁ Kite ▁ = ▁ " + areaOfKite ( d1 , d2 ) ) ; } }


"Program to calculate the area of Kite | C # implementation of the approach ; Function to return the area of the kite ; convert angle degree to radians ; use above formula ; Driver code"
Solution in C#:

using System ; class GFG { static double PI = ( 3.14159 / 180 ) ; static float areaOfKite ( int a , int b , double angle ) { angle = angle * PI ; double area = a * b * Math . Sin ( angle ) ; return ( float ) area ; } static public void Main ( ) { int a = 4 , b = 7 , angle = 78 ; Console . WriteLine ( " Area ▁ of ▁ Kite ▁ = ▁ " + areaOfKite ( a , b , angle ) ) ; } }