Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/107/10783/a.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 tot;
   54     int i;
   55 
   56     tot = 0;
   57     a = a | 1; /* make sure a is odd. */
   58     for (i=a; i<=b; i=i+2)
   59         {
   60             tot = tot + i;
   61         }
   62     printf("%d\n", tot);
   63 } /* FUNCTION process */
   64 
   65 int main ()
   66 {
   67     /* main */
   68     int i;
   69 
   70     init();
   71     for (i=0; i<numberOfTimes; i++)
   72         {
   73             /* while */
   74             getInput();
   75             DEBUG printf("%d %d - ", a, b);
   76             printf("Case %d: ", i+1);
   77             process();
   78         } /* while */
   79 
   80     return EXIT_SUCCESS;
   81 } /* main */
   82 
   83