Chuyển sang C++ giúp mình với ạ 1:
uses crt;
var a,b,i,tsc,tsl:integer;
begin
clrscr;
write('nhap a='); readln(a);
write('nhap b='); readln(b);
if (a>0) and (b>0) then
begin
if a<b then
begin
tsc:=0;
tsl:=0;
for i:=a to b do
if i mod 2=0 then tsc:=tsc+i
else tsl:=tsl+i;
writeln('tong cac so chan trong khoang tu ',a,' toi ',b,' la: ',tsc);
writeln('tong cac so le trong khoang tu ',a,' toi ',b,' la: ',tsl);
end
else writeln('vui long nhap a be hon b');
end
else writeln('vui long nhap hai so duong');
readln;
end.
#include <bits/stdc++.h>
using namespace std;
int a,b,s1,s2,s;
int main()
{
cin>>a>>b;
s1=0; s2=0;
for (int i=a; i<=b; i++)
{
if (i%2==0) s1+=i;
else s2+=i;
}
cout<<s1<<endl;
cout<<s2;
return 0;
}