Changes between Version 1 and Version 2 of FactorialExample
- Timestamp:
- 01/03/06 05:51:29 (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
FactorialExample
v1 v2 11 11 {{{ 12 12 #!d 13 uint factorial(int a) 14 { 13 import std.stdio; 14 15 uint factorial(int a) { 15 16 /* 16 A factorial is a mathematical concept that is typically denoted with a "!". 17 18 Example: 19 4! = 4 * 3 * 2 * 1 = 24 17 A factorial is a mathematical concept that is typically denoted with a "!". 18 Example: 19 4! = 4 * 3 * 2 * 1 = 24 20 20 */ 21 22 21 23 22 if(a == 0) return 1; 29 28 } 30 29 31 32 import std.c.stdio;33 34 30 unittest 35 31 { 36 32 /* Compile with the "-unittest" option to run these unittests. */ 37 33 38 printf("Attempting unittests...\n");34 writefln("Attempting unittests..."); 39 35 assert(factorial(0) == 1); 40 36 assert(factorial(1) == 1); 42 38 assert(factorial(3) == 6); 43 39 assert(factorial(4) == 24); 44 printf("unittests successful...\n");40 writefln("unittests successful..."); 45 41 } 46 42 48 44 void main() 49 45 { 50 printf("factorial(0): %d\n", factorial(0));51 printf("factorial(1): %d\n", factorial(1));52 printf("factorial(2): %d\n", factorial(2));53 printf("factorial(3): %d\n", factorial(3));54 printf("factorial(4): %d\n", factorial(4));46 writefln("factorial(0): %d", factorial(0)); 47 writefln("factorial(1): %d", factorial(1)); 48 writefln("factorial(2): %d", factorial(2)); 49 writefln("factorial(3): %d", factorial(3)); 50 writefln("factorial(4): %d", factorial(4)); 55 51 } 56 52 }}} 57 58 == Source ==59 60 || Link || http://www.dsource.org/tutorials/index.php?show_example=63 ||61 || Posted by || jcc7 ||62 || Date/Time || Mon May 3, 2004 12:18 am ||