Solution of URI 1101::Sequence of Numbers and Sum
Before seeing the solution make sure that you have tried enough. Don’t copy the whole code, just find out the logic. If you feel any problem, you will inform me by comment.
#include <stdio.h>
int main()
{
int M,N,i,small,big;
long long int sum=0;
while(scanf("%d%d",&M,&N) !=EOF) {
if(M<=0 || N<=0) {
return 0;
}
small=M<N? M:N;
big=M>N? M:N;
for(i=small;i<=big;i++) {
sum+=i;
printf("%d ",i);
}
printf("Sum=%lld\n",sum);
sum=0;
}
return 0;
}
No comments