Squares in N*N Chessboard
PROBLEM :
Find total number of Squares in a N*N cheesboard.
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 seperate line showing the maximum number of squares possible.
Constraints:
1 = T = 100
1 = N = 100
Example:
Input :
2
1
2
Output :
1
5
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
long long Total_square(int ) ;
int main()
{
int t,no ;
cin>>t ;
while(t--)
{
cin>>no ;
cout<<Total_square(no) ;
cout<<endl ;
}
return 0;
}
long long Total_square(int no)
{
long long count=0 ;
while(no)
{
count=count+no*no ;
no-- ;
}
return count ;
}
---------------------------------------------------------------------------------
Find total number of Squares in a N*N cheesboard.
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 seperate line showing the maximum number of squares possible.
Constraints:
1 = T = 100
1 = N = 100
Example:
Input :
2
1
2
Output :
1
5
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
long long Total_square(int ) ;
int main()
{
int t,no ;
cin>>t ;
while(t--)
{
cin>>no ;
cout<<Total_square(no) ;
cout<<endl ;
}
return 0;
}
long long Total_square(int no)
{
long long count=0 ;
while(no)
{
count=count+no*no ;
no-- ;
}
return count ;
}
---------------------------------------------------------------------------------
Comments
Post a Comment