Number of perfect cubes between two given numbers | A Simple Method to count cubes between a and b ; Function to count cubes between two numbers ; Traverse through all numbers ; Check if current number ' i ' is perfect cube ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countCubes ( int a , int b ) { for ( int i = a ; i <= b ; i ++ ) for ( int j = 1 ; j * j * j <= i ; j ++ ) if ( j * j * j == i ) cnt ++ ; return cnt ; } int main ( ) { int a = 7 , b = 30 ; cout << " Count ▁ of ▁ Cubes ▁ is ▁ " << countCubes ( a , b ) ; return 0 ; }