Leyland Number | C # program to print first N Leyland Numbers . ; Print first n Leyland Number . ; Outer loop for x from 2 to n . ; Inner loop for y from 2 to x . ; Calculating x ^ y + y ^ x ; Sorting the all Leyland Number . ; Printing first n Leyland number . ; Driver Code
using System ; using System . Collections ; class GFG { public static void leyland ( int n ) { ArrayList ans = new ArrayList ( ) ; for ( int x = 2 ; x <= n ; x ++ ) { for ( int y = 2 ; y <= x ; y ++ ) { int temp = ( int ) Math . Pow ( x , y ) + ( int ) Math . Pow ( y , x ) ; ans . Add ( temp ) ; } } ans . Sort ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( ans [ i ] + " ▁ " ) ; } } public static void Main ( ) { int n = 6 ; leyland ( n ) ; } }