Find the number of squares inside the given square grid | C ++ implementation of the approach ; Function to return the number of squares inside an n * n grid ; Driver code
#include <iostream> NEW_LINE using namespace std ; int cnt_squares ( int n ) { return n * ( n + 1 ) * ( 2 * n + 1 ) / 6 ; } int main ( ) { cout << cnt_squares ( 4 ) << endl ; return 0 ; }