Read a undetermined number of pairs values * M *and

**(stop when any of these values is less or equal to zero). For each pair, print the sequence from the smallest to the biggest (including both) and the sum of consecutive integers between them (including both).**

*N*## Input

The input file contains pairs of integer values * M *and

**. The last line of the file contain a number zero or negative, or both.**

*N*## Output

For each pair of values??, print the sequence from the smallest to the biggest and the sum of these values, as shown below.

Sample Input | Sample Output |

5 2 6 3 5 0 |
2 3 4 5 Sum=14 3 4 5 6 Sum=18 |

Solution:

#include <cstdio>int main(){ int i, j, x, z, s; while (scanf("%d %d", &i, &j) && i > 0 && j > 0) { s = 0; if (j < i){ x = i; i = j; j = x; } for (z = i; z <= j; z++){ printf("%d ", z); s += z; } printf("Sum=%d\n", s); } return 0; }

Advertisements