From bf58faca55fa390ce6a3beae655d45118af778c5 Mon Sep 17 00:00:00 2001 From: Denis Costa Date: Thu, 22 Aug 2024 17:09:23 -0300 Subject: [PATCH] Solve Sum of Consecutive Odd Numbers II in c --- solutions/beecrowd/1099/1099.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 solutions/beecrowd/1099/1099.c diff --git a/solutions/beecrowd/1099/1099.c b/solutions/beecrowd/1099/1099.c new file mode 100644 index 00000000..eeb6882c --- /dev/null +++ b/solutions/beecrowd/1099/1099.c @@ -0,0 +1,34 @@ +#include +#include + +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; +}