Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/4/495/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 <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 int num;
   28 
   29 void init()
   30 {
   31     /* FUNCTION init */
   32 } /* FUNCTION init */
   33 
   34 void dump()
   35 {
   36     /* FUNCTION dump */
   37 } /* FUNCTION dump */
   38 
   39 int getInput()
   40 {
   41     /* FUNCTION getInput */
   42     int dataReadFlag;
   43 
   44     dataReadFlag = (1 == scanf(" %d ", &num));
   45     return (dataReadFlag);
   46 } /* FUNCTION getInput */
   47 
   48 int fib(int i)
   49 {
   50     /* FUNCTION fib */
   51     int toReturn;
   52 
   53     switch (i)
   54         {
   55         /* switch */
   56         case 0:
   57             toReturn = 0;
   58             break;
   59         case 1:
   60             toReturn = 1;
   61             break;
   62         default:
   63             toReturn = fib(i-1) + fib(i-2);
   64         } /* switch */
   65     return toReturn;
   66 } /* FUNCTION fib */
   67 
   68 void process()
   69 {
   70     /* FUNCTION process */
   71     int fnum;
   72 
   73     fnum=fib(num);
   74     printf("The Fibonacci number for %d is %d\n", num, fnum);
   75 } /* FUNCTION process */
   76 
   77 int main()
   78 {
   79     /* main */
   80     int moreToDo;
   81 
   82     init();
   83     moreToDo = getInput();
   84     while (moreToDo)
   85         {
   86             /* while */
   87             process();
   88             moreToDo = getInput();
   89         } /* while */
   90 
   91     return EXIT_SUCCESS;
   92 } /* main */
   93