Puzzle | Program to find number of squares in a chessboard | C # find number of squares in a chessboard ; Function to return count of squares ; ; A better way to write n * ( n + 1 ) * ( 2 n + 1 ) / 6 ; Driver code
using System ; public class GFG { static int countSquares ( int n ) { return ( n * ( n + 1 ) / 2 ) * ( 2 * n + 1 ) / 3 ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( " Count ▁ of " + " squares ▁ is ▁ " + countSquares ( n ) ) ; } }