Số chẵn:
Var i,n,S: longint;
Begin
Readln(n);
For i:=1 to n do
If i mod 2 = 0 then S:=S+i
Write(S);
Readln
End.
Số lẻ:
Var i,n,S: longint;
Begin
Readln(n);
For i:=1 to n do
If i mod 2 = 1 then S:=S+i
Write(S);
Readln
End.
#include <bits/stdc++.h>
using namespace std;
long long x,n,i,t1,t2;
int main()
{
cin>>n;
t1=0;
t2=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%2==0) t1+=x;
else t2+=x;
}
cout<<t1<<" "<<t2;
return 0;
}