Magos code is almost right then. Make a minor change and it should work.

Code:
int TotalSum = 0;
for(int i=x; i<=y; i++) 
TotalSum += i;
//print TotalSum