Computer Programming Contest Preparation

ToolBox - Source for: 4/495/a.c



/home/toolbox/public_html/solutions/4/495/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 <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 
   16 /*
   17  *  Author: Isaac Traxler
   18  *    Date: 2015-03-12
   19  * Purpose:
   20  * Problem: 495
   21  */
   22 
   23 /*
   24  * This template reads lines of data at a time until end of file.
   25  */
   26 
   27 #define LAST_NUMBER 5002
   28 
   29 int num;
   30 unsigned long long int fib[LAST_NUMBER];
   31 
   32 void init()
   33 {
   34     /* FUNCTION init */
   35     int i;
   36 
   37     fib[0] =0;
   38     fib[1] = 1;
   39     for (i=2; i<LAST_NUMBER; i++)
   40         {
   41             /* calculate fib number */
   42             fib[i] = fib[i-1] + fib[i-2];
   43         } /* calculate fib number */
   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     dataReadFlag = (1 == scanf(" %d ", &num));
   57     return (dataReadFlag);
   58 } /* FUNCTION getInput */
   59 
   60 void process()
   61 {
   62     /* FUNCTION process */
   63     printf("The Fibonacci number for %d is %u\n", num, fib[num]);
   64 } /* FUNCTION process */
   65 
   66 int main()
   67 {
   68     /* main */
   69     int moreToDo;
   70 
   71     init();
   72     moreToDo = getInput();
   73     while (moreToDo)
   74         {
   75             /* while */
   76             process();
   77             moreToDo = getInput();
   78         } /* while */
   79 
   80     return EXIT_SUCCESS;
   81 } /* main */
   82