Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes between Version 1 and Version 2 of FactorialExample

Show
Ignore:
Author:
csauls (IP: 69.166.134.113)
Timestamp:
01/03/06 05:51:29 (15 years ago)
Comment:

Updated to use writef, removed "Source" section, and other miscellany.

Legend:

Unmodified
Added
Removed
Modified
  • FactorialExample

    v1 v2  
    1111{{{ 
    1212#!d 
    13 uint factorial(int a) 
    14 
     13import std.stdio; 
     14 
     15uint factorial(int a) { 
    1516    /* 
    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 
    2020    */ 
    21  
    2221 
    2322    if(a == 0) return 1; 
    2928} 
    3029 
    31  
    32 import std.c.stdio; 
    33  
    3430unittest 
    3531{ 
    3632    /* Compile with the "-unittest" option to run these unittests. */ 
    3733 
    38     printf("Attempting unittests...\n"); 
     34    writefln("Attempting unittests..."); 
    3935    assert(factorial(0) == 1); 
    4036    assert(factorial(1) == 1); 
    4238    assert(factorial(3) == 6); 
    4339    assert(factorial(4) == 24); 
    44     printf("unittests successful...\n"); 
     40    writefln("unittests successful..."); 
    4541} 
    4642 
    4844void main() 
    4945{ 
    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)); 
    5551} 
    5652}}} 
    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 ||