Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Calculate the Factorial of an Integer in C#

, 3 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Use Recursion.int factorial(int n){ if(n<0) return -1; if(n==0 || n==1) return 1; return n * factorial(n-1);}
Use Recursion.
int factorial(int n)
{
 if(n<0)
  return -1;
 if(n==0 || n==1)
  return 1;
 
 return n * factorial(n-1);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Anshul R
Student
India India
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 good Pinmembermandar130519-Oct-11 1:25 
GeneralGuys, please. This is a tail-recursion and it won't be any s... Pinmemberckbz18-Oct-11 22:13 
GeneralReason for my vote of 1 Besides, recursion for the sake of r... Pinmembervictorbos18-Oct-11 4:23 
GeneralReason for my vote of 1 The time has long since passed when ... PinadminChris Maunder4-Oct-11 3:47 
GeneralA standard and simple solution, my 5. However, the original ... PinmemberEdward Nutting3-Oct-11 21:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 3 Oct 2011
Article Copyright 2011 by Anshul R
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid