fak.c
changeset 0 af501b0c1716
child 9 c3fecc82ade6
equal deleted inserted replaced
-1:000000000000 0:af501b0c1716
       
     1 /*
       
     2  *     $Id: fak.c,v 1.1.1.1 2008-04-28 17:32:53 mbroeker Exp $
       
     3  * $Source: /development/c/demos/fak.c,v $
       
     4  */
       
     5 
       
     6 #include <stdio.h>
       
     7 #include <stdlib.h>
       
     8 
       
     9 long fak (int i)
       
    10 {
       
    11     if (i == 0)
       
    12         return 1;
       
    13     else if (i > 0)
       
    14         return (i * fak (i - 1));
       
    15     else
       
    16         return (i * fak (i + 1));
       
    17 }
       
    18 
       
    19 int main (int argc, char **argv)
       
    20 {
       
    21     int number;
       
    22 
       
    23     printf ("Enter a number: ");
       
    24     if (scanf ("%d", &number) < 0) {
       
    25         printf ("READ ERROR\n");
       
    26         return EXIT_FAILURE;
       
    27     }
       
    28 
       
    29     printf ("The faktorial of %d is %ld\n", number, fak (number));
       
    30 
       
    31     return EXIT_SUCCESS;
       
    32 }