Computer Programming Contest Preparation

ToolBox - Source for: 107/10783/b.c



/home/toolbox/public_html/solutions/107/10783/b.c
    1 #include <stdio.h>
    2 #include <string.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
    6 #include <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2014-10-28
   20  * Purpose: fun
   21  * Problem: 10783 - Odd Sum
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 int numberOfTimes;
   29 int a;
   30 int b;
   31 
   32 void init()
   33 {
   34     /* FUNCTION init */
   35     scanf("%d ", &numberOfTimes);
   36 } /* FUNCTION init */
   37 
   38 void dump()
   39 {
   40     /* FUNCTION dump */
   41 } /* FUNCTION dump */
   42 
   43 void getInput()
   44 {
   45     /* FUNCTION getInput */
   46 
   47     scanf(" %d %d ", &a, &b);
   48 } /* FUNCTION getInput */
   49 
   50 void process()
   51 {
   52     /* FUNCTION process */
   53     int sum = 0;
   54     int i;
   55 
   56     // if a is even
   57     if (a % 2 == 0)
   58         {
   59 
   60             // then the smallest odd integer we want is one greater than a
   61             a++;
   62         }
   63 
   64 
   65     // go through every odd number from a to b
   66     for (i = a; i <= b; i += 2)
   67         {
   68 
   69             // and add it to the running sum
   70             sum += i;
   71         }
   72 
   73     printf("%d\n", sum);
   74 } /* FUNCTION process */
   75 
   76 int main ()
   77 {
   78     /* main */
   79     int i;
   80 
   81     init();
   82     for (i=0; i<numberOfTimes; i++)
   83         {
   84             /* while */
   85             getInput();
   86             DEBUG printf("%d %d - ", a, b);
   87             printf("Case %d: ", i);
   88             process();
   89         } /* while */
   90 
   91     return EXIT_SUCCESS;
   92 } /* main */
   93 
   94