Chef and Bored Games
Question : Chef and Bored Games
Problem Code: PCJ18B
Solution in C++ :
#include <iostream>
using namespace std;
int check(int n)
{
int t=n-2,sum=0;
if(t<=0)
{
return n*n;
}
else
{
sum=sum+(n*n)+check(t);
return sum;
}
}
int main() {
int tc;
cin>>tc;
for(int i=0;i<tc;i++)
{
int n;
cin>>n;
int odd=check(n);
cout<<odd<<"\n";
}
return 0;
}
Comments
Post a Comment