# Sum a line of numbers

Sum a line of numbers programming exercise.

The dragons of Shan mountain have to do math again. But since the math is not with gold coins, they became bored and offered the following quest:

Given two integers find the sum of all the numbers between including them.
Assume that the integers are not always in ascending order. And also – could be negative.

```Example 1:
1 5
So we need all the numbers between 1 2 3 4 5.
1+2+3+4+5=15
Example 2:
4 -3
Or the number -3 -2 -1 0 1 2 3 4
```

For the solution of this coding problem kindly scroll down.

```    public static int GetSum(int a, int b)
{
//Since all variables are space in memory, they have to
//have .. well space! But how much space ?
//that's what types are. Do you know how much space INT is?
//And don't answer something like: "depend on the hard disk"
int sum = 0;
//lets create the numbers with for loop and sum them
//we have to determine the proper start and end of the loop

if (a>b)
{
for (int i = b; i <= a; i++)
{sum += i;}
}
else
{
for (int i = a; i <= b; i++)
{sum += i;}
}
//returning the result
return sum;
}```