Click here to Skip to main content
12,253,990 members (65,779 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

8.7K views
Posted

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

You may also be interested in...

Comments and Discussions

 
GeneralReason for my vote of 5 good Pin
mandar130519-Oct-11 0:25
membermandar130519-Oct-11 0:25 
GeneralGuys, please. This is a tail-recursion and it won't be any s... Pin
ckbz18-Oct-11 21:13
memberckbz18-Oct-11 21:13 
GeneralReason for my vote of 1 Besides, recursion for the sake of r... Pin
victorbos18-Oct-11 3:23
membervictorbos18-Oct-11 3:23 
GeneralReason for my vote of 1 The time has long since passed when ... Pin
Chris Maunder4-Oct-11 2:47
adminChris Maunder4-Oct-11 2:47 
GeneralA standard and simple solution, my 5. However, the original ... Pin
Edward Nutting3-Oct-11 20:24
memberEdward Nutting3-Oct-11 20:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.160426.1 | Last Updated 3 Oct 2011
Article Copyright 2011 by Anshul R
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid