My issue
include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–)
{
long long a,b=0;
cin>>a;
if(a%2==0)
cout<<a*2<<endl;
else
{
for(int i=2;i<=a;i++)
b=b+a*i;
cout<<b<<endl;
}
}
}
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
long long a,b=0;
cin>>a;
if(a%2==0)
cout<<a*2<<endl;
else
{
for(int i=2;i<=a;i++)
b=b+a*i;
cout<<b<<endl;
}
}
}
Problem Link: Sum of N Practice Coding Problem