Squares in N*N Chessboard
Find total number of Squares in a N*N chessboard.
Input:
The first line contains an integer T, depicting total number of test cases. Then following T lines contains an integer N that is the side of the chessboard.
Output:
Each separate line showing the maximum number of squares possible.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 100
Example:
Input:
2
1
2
Output:
1
5
Solution:
CPP
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int sum=0;
for(int i=1;i<=n;i++)
{
sum=sum+i*i;
}
cout<<sum<<endl;
}
return 0;
}
Interesting and helpful.
ReplyDelete