blob: 4804bc2b7ce2d96e8ca681ac107608d545db1d1f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Factorial
using System;
public class Test
{
public static int Main(string[] args)
{
Test app = new Test();
app.Run(args);
return (100);
}
public int Run(string[] args)
{
long i;
if (args.Length == 0)
{
i = 17;
}
else if (args.Length == 1)
{
i = Convert.ToInt64(args[0]);
}
else
{
usage();
return (1);
}
Console.Out.WriteLine("Factorial of " + i.ToString() + " is " + Fact(i).ToString());
return (0);
}
private long Fact(long i)
{
if (i <= 1L)
return (i);
return (i * Fact(i - 1L));
}
private void usage()
{
Console.Out.WriteLine("usage: Fact [number]");
}
}
|