Calculate Factorial


/ Published in: C#
Save to your folder(s)

Just compile in your command line and run

how to compile : csc Factorial.cs


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.