Perfect cubes in a range | C # progroam for Efficient method to print cubes between a and b ; An efficient solution to print perfect cubes between a and b ; Find cube root of both a and b ; Print cubes between acrt and bcrt ; Driver Code
using System ; class GFG { static void printCubes ( int a , int b ) { int acrt = ( int ) Math . Pow ( a , ( double ) 1 / 3 ) ; int bcrt = ( int ) Math . Pow ( b , ( double ) 1 / 3 ) ; for ( int i = acrt ; i <= bcrt ; i ++ ) if ( i * i * i >= a && i * i * i <= b ) Console . Write ( i * i * i + " ▁ " ) ; } static public void Main ( ) { int a = 24 ; int b = 576 ; Console . WriteLine ( " Perfect ▁ cubes ▁ " + " in ▁ given ▁ range : " ) ; printCubes ( a , b ) ; } }