Posted By

indra on 10/29/10


Tagged

algorithm


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Calculate Factorial


 / Published in: C#
 

Just compile in your command line and run

how to compile : csc Factorial.cs

  1. public class Factorial
  2. {
  3.  
  4. public static void Main(string[] args)
  5. {
  6. string op;
  7.  
  8. System.Console.Write("Input number : ");
  9. op = System.Console.ReadLine();
  10. System.Console.WriteLine(CalculateFactorial(int.Parse(op)));
  11. }
  12.  
  13. public static int CalculateFactorial(int pNumber)
  14. {
  15. int result = 1;
  16. for (int i = 1; i <= pNumber; i++)
  17. {
  18. result = result * i;
  19. }
  20. return result;
  21. }
  22.  
  23. }

Report this snippet  

You need to login to post a comment.