Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,955 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,653 people online right now. Registration is fast and FREE... Join Now!




Finding permutations using iterative and recursive factorial functions

 
Reply to this topicStart new topic

Finding permutations using iterative and recursive factorial functions

harry4uall
9 May, 2008 - 10:20 PM
Post #1

New D.I.C Head
*

Joined: 24 Apr, 2008
Posts: 1

#include<iostream>
#include<cmath>

using namespace std;

int ite_factorial(int n);
int rec_factorial(int n);
int perm_i(int n, int k);
int perm_r(int n, int k);

int main()
{
int n,k;

cout <<"Enter number of k items : ";
cin >> k;
cout << "Enter numbers in the set (n) : ";
cin >> n;

cout <<"Permutation calculated using iterative factorial function : " << perm_i << endl;
cout <<"Permutation calculated using recursive factorial function : " << perm_r << endl;


return 0;
}

int ite_factorial(int n)
{
int accu = 1;
int i;
for(i = 1; i <= n; i++) {
accu *= i;
}
return accu;
}


int rec_factorial(int n)
{
if( n == 1)
return 1;
else
{
return (n * (rec_factorial(n-1)));
}
}

int perm_i(int n, int k)
{
int P;
while(n >= 0)
{
P = ite_factorial(n)/ite_factorial(n-k);

}

return P;
}
int perm_r(int n, int k)
{
int P;
while(n >= 0)
{
P = rec_factorial(n)/rec_factorial(n-k);

}

return P;
}



Attached File(s)
Attached File  a3.pdf ( 40.48k ) Number of downloads: 52
User is offlineProfile CardPM
+Quote Post

skaoth
RE: Finding Permutations Using Iterative And Recursive Factorial Functions
10 May, 2008 - 01:42 PM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 342



Thanked: 10 times
Dream Kudos: 100
My Contributions
are you having problems with any of these in particular? And if so which one? It is best for everyone of you point us at the problem area instead of having us figure it out ourselves. After all this most of us are using our free time to help.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:14AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month