codeparrot/xlcost-text-to-code huggingface dataset:
Remove nodes on root to leaf paths of length < K | C # program to remove nodes on root to leaf paths of length < k ; Class containing left and right child of current node and key value ; Utility method that actually removes the nodes which are not on the pathLen >= k . This method can change the root as well . ; Base condition ; Traverse the tree in postorder fashion so that if a leaf node path length is shorter than k , then that node and all of its descendants till the node which are not on some other path are removed . ; If root is a leaf node and it 's level is less than k then   remove this node.   This goes up and check for the ancestor nodes also for the   same condition till it finds a node which is a part of other   path(s) too.  ; Return root ; ; Method which calls the utitlity method to remove the short path nodes . ; Method to print the tree in inorder fashion . ; Driver program to test for samples
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { public Node root ; public virtual Node removeShortPathNodesUtil ( Node node , int level , int k ) { if ( node == null ) { return null ; } node . left = removeShortPathNodesUtil ( node . left , level + 1 , k ) ; node . right = removeShortPathNodesUtil ( node . right , level + 1 , k ) ; if ( node . left == null && node . right == null && level < k ) { return null ; } return node ; } public virtual Node removeShortPathNodes ( Node node , int k ) { int pathLen = 0 ; return removeShortPathNodesUtil ( node , 1 , k ) ; } public virtual void printInorder ( Node node ) { if ( node != null ) { printInorder ( node . left ) ; Console . Write ( node . data + " ▁ " ) ; printInorder ( node . right ) ; } } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; int k = 4 ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . left . left . left = new Node ( 7 ) ; tree . root . right . right = new Node ( 6 ) ; tree . root . right . right . left = new Node ( 8 ) ; Console . WriteLine ( " The ▁ inorder ▁ traversal ▁ of ▁ original ▁ tree ▁ is ▁ : ▁ " ) ; tree . printInorder ( tree . root ) ; Node res = tree . removeShortPathNodes ( tree . root , k ) ; Console . WriteLine ( " " ) ; Console . WriteLine ( " The ▁ inorder ▁ traversal ▁ of ▁ modified ▁ tree ▁ is ▁ : ▁ " ) ; tree . printInorder ( res ) ; } }
Remove duplicates from a given string | C # program to remove duplicate character from character array and print in sorted order ; Create a set using String characters excluding ' \0' ; Print content of the set ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static char [ ] removeDuplicate ( char [ ] str , int n ) { HashSet < char > s = new HashSet < char > ( n - 1 ) ; foreach ( char x in str ) s . Add ( x ) ; char [ ] st = new char [ s . Count ] ; int i = 0 ; foreach ( char x in s ) st [ i ++ ] = x ; return st ; } public static void Main ( String [ ] args ) { char [ ] str = " geeksforgeeks " . ToCharArray ( ) ; int n = str . Length ; Console . Write ( removeDuplicate ( str , n ) ) ; } }
Sudoku | Backtracking | C # program for above approach ; N is the size of the 2D matrix N * N ; A utility function to print grid ; Check whether it will be legal to assign num to the given row , col ; Check if we find the same num in the similar row , we return false ; Check if we find the same num in the similar column , we return false ; Check if we find the same num in the particular 3 * 3 matrix , we return false ; Takes a partially filled - in grid and attempts to assign values to all unassigned locations in such a way to meet the requirements for Sudoku solution ( non - duplication across rows , columns , and boxes ) ; if we have reached the 8 th row and 9 th column ( 0 indexed matrix ) , we are returning true to avoid further backtracking ; Check if column value becomes 9 , we move to next row and column start from 0 ; Check if the current position of the grid already contains value > 0 , we iterate for next column ; Check if it is safe to place the num ( 1 - 9 ) in the given row , col -> we move to next column ; assigning the num in the current ( row , col ) position of the grid and assuming our assigned num in the position is correct ; Checking for next possibility with next column ; removing the assigned num , since our assumption was wrong , and we go for next assumption with diff num value ; Driver code ; 0 means unassigned cells
using System ; class GFG { static int N = 9 ; static void print ( int [ , ] grid ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) Console . Write ( grid [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } static bool isSafe ( int [ , ] grid , int row , int col , int num ) { for ( int x = 0 ; x <= 8 ; x ++ ) if ( grid [ row , x ] == num ) return false ; for ( int x = 0 ; x <= 8 ; x ++ ) if ( grid [ x , col ] == num ) return false ; int startRow = row - row % 3 , startCol = col - col % 3 ; for ( int i = 0 ; i < 3 ; i ++ ) for ( int j = 0 ; j < 3 ; j ++ ) if ( grid [ i + startRow , j + startCol ] == num ) return false ; return true ; } static bool solveSuduko ( int [ , ] grid , int row , int col ) { if ( row == N - 1 && col == N ) return true ; if ( col == N ) { row ++ ; col = 0 ; } if ( grid [ row , col ] != 0 ) return solveSuduko ( grid , row , col + 1 ) ; for ( int num = 1 ; num < 10 ; num ++ ) { if ( isSafe ( grid , row , col , num ) ) { grid [ row , col ] = num ; if ( solveSuduko ( grid , row , col + 1 ) ) return true ; } grid [ row , col ] = 0 ; } return false ; } static void Main ( ) { int [ , ] grid = { { 3 , 0 , 6 , 5 , 0 , 8 , 4 , 0 , 0 } , { 5 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 8 , 7 , 0 , 0 , 0 , 0 , 3 , 1 } , { 0 , 0 , 3 , 0 , 1 , 0 , 0 , 8 , 0 } , { 9 , 0 , 0 , 8 , 6 , 3 , 0 , 0 , 5 } , { 0 , 5 , 0 , 0 , 9 , 0 , 6 , 0 , 0 } , { 1 , 3 , 0 , 0 , 0 , 0 , 2 , 5 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 4 } , { 0 , 0 , 5 , 2 , 0 , 6 , 3 , 0 , 0 } } ; if ( solveSuduko ( grid , 0 , 0 ) ) print ( grid ) ; else Console . WriteLine ( " No ▁ Solution ▁ exists " ) ; } }
Given an array A [ ] and a number x , check for pair in A [ ] with sum as x | C # implementation using Hashing ; function to check for the given sum in the array ; checking for condition ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void printpairs ( int [ ] arr , int sum ) { HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < arr . Length ; ++ i ) { int temp = sum - arr [ i ] ; if ( s . Contains ( temp ) ) { Console . Write ( " Pair ▁ with ▁ given ▁ sum ▁ " + sum + " ▁ is ▁ ( " + arr [ i ] + " , ▁ " + temp + " ) " ) ; } s . Add ( arr [ i ] ) ; } } static void Main ( ) { int [ ] A = new int [ ] { 1 , 4 , 45 , 6 , 10 , 8 } ; int n = 16 ; printpairs ( A , n ) ; } }
Longest consecutive sequence in Binary tree | C # program to find longest consecutive sequence in binary tree ; A binary tree node has data , pointer to left child and a pointer to right child ; Utility method to return length of longest consecutive sequence of tree ; if root data has one more than its parent then increase current length ; update the maximum by current length ; recursively call left and right subtree with expected value 1 more than root data ; method returns length of longest consecutive sequence rooted at node root ; call utility method with current length 0 ; Driver code
using System ; class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class Result { public int res = 0 ; } class GFG { Node root ; private void longestConsecutiveUtil ( Node root , int curlength , int expected , Result res ) { if ( root == null ) return ; if ( root . data == expected ) curlength ++ ; else curlength = 1 ; res . res = Math . Max ( res . res , curlength ) ; longestConsecutiveUtil ( root . left , curlength , root . data + 1 , res ) ; longestConsecutiveUtil ( root . right , curlength , root . data + 1 , res ) ; } int longestConsecutive ( Node root ) { if ( root == null ) return 0 ; Result res = new Result ( ) ; longestConsecutiveUtil ( root , 0 , root . data , res ) ; return res . res ; } public static void Main ( String [ ] args ) { GFG tree = new GFG ( ) ; tree . root = new Node ( 6 ) ; tree . root . right = new Node ( 9 ) ; tree . root . right . left = new Node ( 7 ) ; tree . root . right . right = new Node ( 10 ) ; tree . root . right . right . right = new Node ( 11 ) ; Console . WriteLine ( tree . longestConsecutive ( tree . root ) ) ; } }
Find remainder when a number A raised to N factorial is divided by P | package whatever do not write package name here ; Function to calculate ( A ^ N ! ) % P in O ( log y ) ; Initialize result ; Update x if it is more than or Equal to p ; In case x is divisible by p ; ; If y is odd , multiply x with result ; y must be even now ; Returning modular power ; Function to calculate resultant remainder ; Initializing ans to store final remainder ; Calculating remainder ; Returning resultant remainder ; Driver Code ; Given Input ; Function Call
using System ; class GFG { static long power ( long x , long y , long p ) { long res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static long remainder ( long n , long a , long p ) { long ans = a % p ; for ( long i = 1 ; i <= n ; i ++ ) ans = power ( ans , i , p ) ; return ans ; } public static void Main ( String [ ] args ) { long A = 2 , N = 1 , P = 2 ; Console . Write ( remainder ( N , A , P ) ) ; } }
Find all array elements occurring more than âŒŠN / 3 âŒ ‹ times | C # program to find if any element appears more than n / 3 ; take the integers as the maximum value of integer hoping the integer would not be present in the array ; if this element is previously seen , increment count1 . ; if this element is previously seen , increment count2 . ; if current element is different from both the previously seen variables , decrement both the counts . ; Again traverse the array and find the actual counts . ; Driver code
using System ; class GFG { static void findMajority ( int [ ] arr , int n ) { int count1 = 0 , count2 = 0 ; int flag = 0 ; int first = Int32 . MinValue ; int second = Int32 . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( first == arr [ i ] ) count1 ++ ; else if ( second == arr [ i ] ) count2 ++ ; else if ( count1 == 0 ) { count1 ++ ; first = arr [ i ] ; } else if ( count2 == 0 ) { count2 ++ ; second = arr [ i ] ; } else { count1 -- ; count2 -- ; } } count1 = 0 ; count2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == first ) count1 ++ ; else if ( arr [ i ] == second ) count2 ++ ; } if ( count1 > n / 3 ) { Console . Write ( first + " ▁ " ) ; flag = 1 ; } if ( count2 > n / 3 ) { Console . Write ( second + " ▁ " ) ; flag = 1 ; } if ( flag == 0 ) Console . Write ( " No ▁ Majority ▁ Element " ) ; } static void Main ( ) { int [ ] arr = { 2 , 2 , 3 , 1 , 3 , 2 , 1 , 1 } ; int n = arr . Length ; findMajority ( arr , n ) ; } }
Modular Exponentiation of Complex Numbers | C # implementation of the approach ; Utility function ; Function to multiply two complex numbers modulo M ; Multiplication of two complex numbers is ( a + ib ) ( c + id ) = ( ac - bd ) + i ( ad + bc ) ; Return the multiplied value ; Function to calculate the complex modular exponentiation ; Here , res is initialised to ( 1 + i0 ) ; If k is odd ; Multiply ' complex ' with ' res ' ; Make complex as complex * complex ; Make k as k / 2 ; Return the required answer ; Driver code ; Function call
using System ; class GFG { public class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static pair Multiply ( pair p , pair q , int M ) { int x = ( ( p . first * q . first ) % M - ( p . second * q . second ) % M + M ) % M ; int y = ( ( p . first * q . second ) % M + ( p . second * q . first ) % M ) % M ; return new pair ( x , y ) ; } static pair compPow ( pair complex , int k , int M ) { pair res = new pair ( 1 , 0 ) ; while ( k > 0 ) { if ( k % 2 == 1 ) { res = Multiply ( res , complex , M ) ; } complex = Multiply ( complex , complex , M ) ; k = k >> 1 ; } return res ; } public static void Main ( String [ ] args ) { int A = 7 , B = 3 , k = 10 , M = 97 ; pair ans = compPow ( new pair ( A , B ) , k , M ) ; Console . WriteLine ( ans . first + " ▁ + ▁ i " + ans . second ) ; } }
Sum of maximum of all subarrays | Divide and Conquer | C # implementation of the above approach ; Array to store segment tree . In first we will store the maximum of a range In second , we will store index of that range ; Size of array declared global to maintain simplicity in code ; Function to build segment tree ; Base case ; Finding the maximum among left and right child ; Returning the maximum to parent ; Function to perform range - max query in segment tree ; Base cases ; Finding the maximum among left and right child ; Function to find maximum sum subarray ; base case ; range - max query to determine largest in the range . ; divide the array in two parts ; Driver Code ; Input array ; Size of array ; Builind the segment - tree
using System ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static readonly int seg_max = 51 ; static pair [ ] seg_tree = new pair [ seg_max ] ; static int n ; static pair buildMaxTree ( int l , int r , int i , int [ ] arr ) { if ( l == r ) { seg_tree [ i ] = new pair ( arr [ l ] , l ) ; return seg_tree [ i ] ; } seg_tree [ i ] = max ( buildMaxTree ( l , ( l + r ) / 2 , 2 * i + 1 , arr ) , buildMaxTree ( ( l + r ) / 2 + 1 , r , 2 * i + 2 , arr ) ) ; return seg_tree [ i ] ; } static pair rangeMax ( int l , int r , int [ ] arr , int i , int sl , int sr ) { if ( sr < l sl > r ) return new pair ( int . MinValue , - 1 ) ; if ( sl >= l && sr <= r ) return seg_tree [ i ] ; return max ( rangeMax ( l , r , arr , 2 * i + 1 , sl , ( sl + sr ) / 2 ) , rangeMax ( l , r , arr , 2 * i + 2 , ( sl + sr ) / 2 + 1 , sr ) ) ; } static pair max ( pair f , pair s ) { if ( f . first > s . first ) return f ; else return s ; } static int maxSumSubarray ( int [ ] arr , int l , int r ) { if ( l > r ) return 0 ; pair a = rangeMax ( l , r , arr , 0 , 0 , n - 1 ) ; return a . first * ( r - a . second + 1 ) * ( a . second - l + 1 ) + maxSumSubarray ( arr , l , a . second - 1 ) + maxSumSubarray ( arr , a . second + 1 , r ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 1 , 7 } ; n = arr . Length ; buildMaxTree ( 0 , n - 1 , 0 , arr ) ; Console . Write ( maxSumSubarray ( arr , 0 , n - 1 ) ) ; } }
Modular exponentiation ( Recursive ) | Recursive C # program to compute modular power ; Base cases ; If B is even ; If B is odd ; Driver Code
class GFG { static int exponentMod ( int A , int B , int C ) { if ( A == 0 ) return 0 ; if ( B == 0 ) return 1 ; long y ; if ( B % 2 == 0 ) { y = exponentMod ( A , B / 2 , C ) ; y = ( y * y ) % C ; } else { y = A % C ; y = ( y * exponentMod ( A , B - 1 , C ) % C ) % C ; } return ( int ) ( ( y + C ) % C ) ; } public static void Main ( ) { int A = 2 , B = 5 , C = 13 ; System . Console . WriteLine ( " Power ▁ is ▁ " + exponentMod ( A , B , C ) ) ; } }
Find frequency of each element in a limited range array in less than O ( n ) time | C # program to count number of occurrences of each element in the array in O ( n ) time and O ( 1 ) space ; check if the current element is equal to previous element . ; reset the frequency ; print the last element and its frequency ; Driver code
using System ; class GFG { public static void findFrequencies ( int [ ] ele ) { int freq = 1 ; int idx = 1 ; int element = ele [ 0 ] ; while ( idx < ele . Length ) { if ( ele [ idx - 1 ] == ele [ idx ] ) { freq ++ ; idx ++ ; } else { Console . WriteLine ( element + " ▁ " + freq ) ; element = ele [ idx ] ; idx ++ ; freq = 1 ; } } Console . WriteLine ( element + " ▁ " + freq ) ; } public static void Main ( String [ ] args ) { Console . WriteLine ( " - - - frequencies ▁ in ▁ a ▁ sorted ▁ array - - - - " ) ; findFrequencies ( new int [ ] { 10 , 20 , 30 , 30 , 30 , 40 , 50 , 50 , 50 , 50 , 70 } ) ; } }
Modular Exponentiation ( Power in Modular Arithmetic ) | Iterative Function to calculate ( x ^ y ) in O ( log y ) ; Initialize result ; If y is odd , multiply x with result ; y must be even now y = y / 2 ; Change x to x ^ 2
static int power ( int x , int y ) { int res = 1 ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = res * x ; y = y >> 1 ; x = x * x ; } return res ; }
Modular Exponentiation ( Power in Modular Arithmetic ) |  ; Iterative Function to calculate ( x ^ y ) in O ( log y ) ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now ; Driver Code
using System ; public class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; y = y >> 1 ; y = y / 2 x = ( x * x ) % p ; } return res ; } static public void Main ( ) { int x = 2 ; int y = 5 ; int p = 13 ; Console . Write ( " Power ▁ is ▁ " + power ( x , y , p ) ) ; } }
Path length having maximum number of bends | C # program to find path length having maximum number of bends ; structure node ; Utility function to create a new node ; Recursive function to calculate the path length having maximum number of bends . The following are parameters for this function . node - . pointer to the current node dir - . determines whether the current node is left or right child of it 's parent node bends -. number of bends so far in the current path. maxBends -. maximum number of bends in a path from root to leaf soFar -. length of the current path so far traversed len -. length of the path having maximum number of bends  ; Base Case ; Leaf node ; Recurring for both left and right child ; Helper function to call findMaxBendsUtil ( ) ; Call for left subtree of the root ; Call for right subtree of the root ; Include the root node as well in the path length ; Driver code ; Constructed binary tree is 10 / \ 8 2 / \ / 3 5 2 \ 1 / 9
using System ; public class GFG { public class Node { public int key ; public Node left ; public Node right ; } ; static Node newNode ( int key ) { Node node = new Node ( ) ; node . left = null ; node . right = null ; node . key = key ; return node ; } static int maxBends ; static int len ; static void findMaxBendsUtil ( Node node , char dir , int bends , int soFar ) { if ( node == null ) return ; if ( node . left == null && node . right == null ) { if ( bends > maxBends ) { maxBends = bends ; len = soFar ; } } else { if ( dir == ' l ' ) { findMaxBendsUtil ( node . left , dir , bends , soFar + 1 ) ; findMaxBendsUtil ( node . right , ' r ' , bends + 1 , soFar + 1 ) ; } else { findMaxBendsUtil ( node . right , dir , bends , soFar + 1 ) ; findMaxBendsUtil ( node . left , ' l ' , bends + 1 , soFar + 1 ) ; } } } static int findMaxBends ( Node node ) { if ( node == null ) return 0 ; len = 0 ; maxBends = - 1 ; int bends = 0 ; if ( node . left != null ) findMaxBendsUtil ( node . left , ' l ' , bends , 1 ) ; if ( node . right != null ) findMaxBendsUtil ( node . right , ' r ' , bends , 1 ) ; len ++ ; return len ; } public static void Main ( String [ ] args ) { Node root = newNode ( 10 ) ; root . left = newNode ( 8 ) ; root . right = newNode ( 2 ) ; root . left . left = newNode ( 3 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 2 ) ; root . right . left . right = newNode ( 1 ) ; root . right . left . right . left = newNode ( 9 ) ; Console . Write ( findMaxBends ( root ) - 1 ) ; } }
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
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 ) ; } }
Sum of sides of largest and smallest child polygons possible from a given polygon | C # program for the above approach ; Function to find the sum of largest and smallest secondary polygons if possible ; Count edges of primary polygon ; Calculate edges present in the largest secondary polygon ; Driver Code ; Given Exterior Angle
using System ; class GFG { static void secondary_polygon ( int Angle ) { int edges_primary = 360 / Angle ; if ( edges_primary >= 6 ) { int edges_max_secondary = edges_primary / 2 ; Console . WriteLine ( edges_max_secondary + 3 ) ; } else Console . WriteLine ( " Not ▁ Possible " ) ; } public static void Main ( string [ ] args ) { int Angle = 45 ; secondary_polygon ( Angle ) ; } }
Area of Circumcircle of an Equilateral Triangle using Median | C # implementation to find the equation of circle which inscribes equilateral triangle of median M ; Function to find the equation of circle whose center is ( x1 , y1 ) and the radius of circle is r ; Function to find the equation of circle which inscribes equilateral triangle of median M ; Function call to find the circle equation ; Driver code ; Function call
using System ; class GFG { static double circleArea ( double r ) { double pi = 3.14159265358979323846 ; return ( pi * r * r ) ; } static double findCircleAreaByMedian ( int m ) { double r = 2 * m / 3 ; return circleArea ( r ) ; } public static void Main ( string [ ] args ) { int m = 3 ; Console . WriteLine ( " { 0 : f4 } " , findCircleAreaByMedian ( m ) ) ; } }
Find the type of triangle from the given sides | C # implementation to find the type of triangle with the help of the sides ; Function to find the type of triangle with the help of sides ; Driver Code ; Function Call
using System ; class GFG { static void checkTypeOfTriangle ( int a , int b , int c ) { int sqa = ( int ) Math . Pow ( a , 2 ) ; int sqb = ( int ) Math . Pow ( b , 2 ) ; int sqc = ( int ) Math . Pow ( c , 2 ) ; if ( sqa == sqa + sqb sqb == sqa + sqc sqc == sqa + sqb ) { Console . Write ( " Right - angled ▁ Triangle " ) ; } else if ( sqa > sqc + sqb sqb > sqa + sqc sqc > sqa + sqb ) { Console . Write ( " Obtuse - angled ▁ Triangle " ) ; } else { Console . Write ( " Acute - angled ▁ Triangle " ) ; } } public static void Main ( String [ ] args ) { int a , b , c ; a = 2 ; b = 2 ; c = 2 ; checkTypeOfTriangle ( a , b , c ) ; } }
Check whether the triangle is valid or not if angles are given | C # program to check validity of any triangle ; Function to check if sum of the three angles is 180 or not ; check condition ; Driver Code ; function calling and print output
using System ; class GFG { public static int Valid ( int a , int b , int c ) { if ( a + b + c == 180 && a != 0 && b != 0 && c != 0 ) return 1 ; else return 0 ; } public static void Main ( ) { int a = 60 , b = 40 , c = 80 ; if ( ( Valid ( a , b , c ) ) == 1 ) Console . WriteLine ( " Valid " ) ; else Console . WriteLine ( " Invalid " ) ; } }