Skip to content

Commit

Permalink
Solve Sum of Consecutive Odd Numbers II in c
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Aug 22, 2024
1 parent 11df12e commit bf58fac
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions solutions/beecrowd/1099/1099.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdint.h>
#include <stdio.h>

int main() {
int32_t n, i, f, x, j, s;

scanf("%d", &n);

while (n--) {
s = 0;

scanf("%d %d", &i, &f);

if (i > f) {
x = i;
i = f;
f = x;
}

i++;

if (i % 2 == 0) {
i++;
}

for (j = i; j < f; j += 2) {
s += j;
}

printf("%d\n", s);
}

return 0;
}

0 comments on commit bf58fac

Please sign in to comment.