author | Markus Bröker <mbroeker@largo.localnet> |
Thu, 16 Apr 2009 12:49:11 +0200 | |
changeset 37 | 0fbbe329c3a2 |
parent 9 | c3fecc82ade6 |
child 63 | 5a82f89d607e |
permissions | -rw-r--r-- |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
1 |
/** |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
2 |
* test/demos/fak.c |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
0
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
0 | 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 |
} |