Question: Language: C Write a function that gets two ints x and y, and returns the sum of all ints between x and y, including them.
Language: C
Write a function that gets two ints x and y, and returns the sum of all ints between x and y, including them.
int sum_interval(int x, int y);
For example: - sum_interval(1, 4)returns 1+2+3+4=10.
- sum_interval(10, 3)returns 3+4+5+6+7+8+9+10=52.
- sum_interval(2, -1)returns (-1)+0+1+2=2.
- sum_interval(-1, -1)returns -1. 1.
Note that we may have x>=y or x<=y. 2.
You may assume that the sum will be within the range of int.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
