View Single Post
  #6 (permalink)  
Old 06-24-2008, 01:27 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 4,074
Last Blog:
Why Learn Data Structu...
Credits: 27
Rep Power: 45
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: Fibonacci with no recursion for fun

Quote:
Originally Posted by samy View Post
Hi WingedPanther!

Would you like to share the fun with us by giving the program for factorials, permutations, and combinations?
Code:
int factorial(int n){
  int fact=1;
  for (int i=1;i<=n;i++) fact*=i;
  return fact;
}

int permutation(int n,r){
  int perm=1;
  for (int i=n-r+1;i<=n;i++) perm*=i;
  return perm;
}

int combination(int n,r){
  return permutation(n,r)/factorial(r);
}
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Reply With Quote