Solution of URI 1099::Sum of Consecutive Odd Numbers II
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 N,X,Y,i,small,big;
long long int sum=0;
scanf("%d",&N);
while(N--) {
scanf("%d%d",&X,&Y);
small=X<Y? X:Y;
big=X>Y? X:Y;
for(i=small+1;i<big;i++) {
if(i%2 !=0) {
sum+=i;
}
}
printf("%lld\n",sum);
sum=0;
}
return 0;
}
No comments