“Sometimes it is the people no one can imagine anything of who do the things no one can imagine.” ― Sir Alan Turing


ADS

ADS

Saturday, April 8, 2017

UVa 10783 Odd Sum Solution in C / C++

 


Source Code 

#include<stdio.h>

int main() {
  int a, b, c, sum, i, j;
  while (scanf("%d", & c) == 1) {
    for (j = 1; j <= c; j++) {
      scanf("%d%d", & a, & b);
      sum = 0;
      if (a % 2 == 0)
        a = a + 1;
      if (b % 2 == 0)
        b = b - 1;
      for (i = a; i <= b; i = i + 2)
        sum = sum + i;
      printf("Case %d: %d\n", j, sum);
    }
  }
  return 0;
}

No comments:

Post a Comment