Answers for "number of squares with odd side length on chessboard"

C++
0

number of squares with odd side length on chessboard

#include <iostream>
using namespace std;

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;// no. of test cases
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;// no. of square in a row or a coloumn of chess board
	    int i=1;
	    int ans=0;
	    while(i<=n)
	    {
	        ans=pow((n-i+1),2);
	        i=i+2;
	    }
	    cout<<ans<<endl;
	}
	return 0;
}
Posted by: Guest on June-05-2021

Browse Popular Code Answers by Language