Computer Programming Contest Preparation

ToolBox - Source for: 121/12149/a.c



/home/toolbox/public_html/solutions/121/12149/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: 2016-09-11
   20  * Purpose: fun
   21  * Problem: 12149 Feynman
   22  */
   23 
   24 /*
   25  * This template reads data until a terminating value is reached.
   26  */
   27 
   28 #define MAX 101
   29 
   30 int a[MAX];
   31 int num;
   32 
   33 void init()
   34 {
   35     /* FUNCTION init */
   36     int i;
   37 
   38     a[1] = 1;
   39     for (i=2; i<MAX; i++)
   40         {
   41             /* for each possible size */
   42             a[i] = (i * i) + a[i-1];
   43         } /* for each possible size */
   44 } /* FUNCTION init */
   45 
   46 void dump()
   47 {
   48     /* FUNCTION dump */
   49 } /* FUNCTION dump */
   50 
   51 int getInput()
   52 {
   53     /* FUNCTION getInput */
   54     int dataReadFlag;
   55 
   56     scanf(" %d ", &num);
   57     dataReadFlag = 0 != num;
   58     return (dataReadFlag);
   59 } /* FUNCTION getInput */
   60 
   61 void process()
   62 {
   63     /* FUNCTION process */
   64     printf("%d\n", a[num]);
   65 } /* FUNCTION process */
   66 
   67 int main()
   68 {
   69     /* main */
   70     int moreToDo;
   71 
   72     init();
   73     moreToDo = getInput();
   74     while (moreToDo)
   75         {
   76             /* while */
   77             process();
   78             moreToDo = getInput();
   79         } /* while */
   80 
   81     return EXIT_SUCCESS;
   82 } /* main */
   83