URI / BEE CROWD 1101 - Sequence of Numbers and Sum - Solution in C,C++,Python | URI - BEECROWD - BEE 1101 Solution in C,C++,Python
beecrowd | 1101
Sequence of Numbers and Sum
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1URI / BEE CROWD 1101 - Sequence of Numbers and Sum - Solution in C,C++,Python | URI - BEECROWD - BEE 1099 Solution in C,C++,Python:
Read an undetermined number of pairs values M and N (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).
Input
The input file contains pairs of integer values M and N. The last line of the file contains a number zero or negative, or both.
Output
For each pair of numbers, print the sequence from the smallest to the biggest and the sum of these values, as shown below.
Input Sample | Output Sample |
5 2 | 2 3 4 5 Sum=14 |
Demonstration:
URI / BEE 1101 Solution in C :
URI / BEECROWD Online Judge 1101 Solve in C : |
#include <stdio.h>
int main(){
int n;
int x, y, aux;
int soma;
while(1){
scanf("%d%d",&x,&y);
if(x <= 0) break;
if(y <= 0) break;
if(x > y){
aux = x;
x = y;
y = aux;
}
soma = 0;
for(int i = x; i <= y; i++){
printf("%d ",i);
soma += i;
}
printf("Sum=%d\n",soma);
}
return 0;
}
What aux means here?
ReplyDeleteaux is a temporary variable for swapping the values.
ReplyDelete