View Single Post
  #1 (permalink)  
Old April 17th, 2008, 07:32 PM
Kreol Kreol is offline
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help with permutation program

My program simply is suppose to calculate the permutation of the two given inputs.. however, I keep getting letters as my answer.. please, this is due tomorrow. can someone please help?





int factorial (unsigned long);
int permutation (unsigned long, unsigned long);
#include <iostream>
using namespace std;

int main()
{
    unsigned long n,r = 0;
cout << "please enter n value " << endl;
    cin >> n;
    cout << "please enter r value " << endl;
    cin >> r;
    cout << "P(" << n << "," << r << ") is equal to.." <<
    cout << permutation(n, r);


    return 0;
}

int factorial(unsigned long number) {
    int temp;

    if(number <= 1) return 1;

    temp = number * factorial(number - 1);
    return temp;
}

int permutation( unsigned long k, unsigned long r)
{
    int result = 0;
    int temp = k - r;

    result = factorial(k)/factorial(r);
    return temp;
}

Reply With Quote