Results 1 to 9 of 9
Ok I just joined this board in hope I can ask this question and that I'm in the right place...
So I have to write a complete program that inputs ...
- 10-07-2008 #1Just Joined!
- Join Date
- Oct 2008
- Posts
- 5
permutaion function C++
Ok I just joined this board in hope I can ask this question and that I'm in the right place...
So I have to write a complete program that inputs n and k and prints out the p(n,k).
This is what I have so far and I'm pretty sure something is incorrect
#include <iostream>
using namespace std;
int main(){
int p,n,k;
cin>>n>>k;
for(P(n,k) = n! / (n - k)!);
{
double factorial(unsigned n) {
if (n == 1) return n;
return n * factorial(n-1);
}
cout<<"p("<<n<<','<<k<<")"<<p<<endl;
}
return 0;
}
Thanks in advance
- 10-08-2008 #2
Is p(n, k) a function?
do you mean your trying to calculate P(n, r) = n!/(n - r)!
- 10-08-2008 #3Just Joined!
- Join Date
- Oct 2008
- Posts
- 5
yes thats what i mean
- 10-08-2008 #4
Well you should define your function outside of the main function like:
Code:#include <iostream> using namespace std; double mypermutation(int x, int y); int main() { int p,n,k; cin>>n>>k; mypermutation(n, k); cout<<"p("<<n<<','<<k<<")"<<p<<endl; return 0; } double mypermutation(int x, int y) { //does whatever it takes to calculate the permutation //return the answer as a double }
- 10-08-2008 #5Just Joined!
- Join Date
- Oct 2008
- Posts
- 5
Sry I'm quite the novice at this but where would that go again?
- 10-08-2008 #6
With respect drummer0702, but gerard4143 pretty much gave you the answer!
If you check out the forum rules you'll see that homework questions aren't allowed. We all had to figure it out in our day -- so do you
Do your best to figure out what gerard4143 meant, and we can try to answer any specific questions you have.
Welcome to the forums
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 10-08-2008 #7Just Joined!
- Join Date
- Oct 2008
- Posts
- 5
Sorry about that. Yah thanks for what help you gave me I'll try and figure it out..Sorry again
- 10-08-2008 #8Just Joined!
- Join Date
- Oct 2008
- Posts
- 5
Okay I figured out what you meant thank you...Now my only problem is that it saying there is a syntax error for 'for' and that something about old style formatting...Idk what the latter is
- 10-09-2008 #9
If you post the program which compiles with the syntax error, we will be better able to help you.
--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote