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

Changes from Version 1 of FactorialExample2

Show
Ignore:
Author:
darkzlayer (IP: 203.177.74.139)
Timestamp:
04/17/10 03:42:29 (14 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FactorialExample2

    v0 v1  
     1 
     2{{{ 
     3/* 
     4 * Factorial using recursive method 
     5 */ 
     6import std.stdio; 
     7 
     8real factorial(uint i) { 
     9        if (i == 0) { 
     10                return 1; 
     11        } else { 
     12                return factorial(i - 1) * i; 
     13        } 
     14} 
     15 
     16int main() 
     17{ 
     18    writef("Enter an unsigned int: "); 
     19        uint i = 0; 
     20         
     21        scanf("%u", &i); 
     22         
     23        writefln(factorial(i)); 
     24 
     25    return 0; 
     26} 
     27}}}