Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Permutations are concerned with order. There are many different orders that we c

ID: 3682644 • Letter: P

Question

Permutations are concerned with order. There are many different orders that we can select to line up the objects in a row. Suppose we have n different objects that can be combined and we select k of the objects. Then there are n!/(n-k)! possible orderings of k objects! A more efficient way to compute permutations is to use the formula P(n,k) = n(n-1)(n-2).....(n-k+2)(n-k+1). This means the product of the k integers from n down to n-k+1. Use this formula to write a function perm( ) and a test driver for the function and confirm that your program works. The test driver should ask the user to input a positive number and should use a break command if the user enters a negative number.

this is what i have so far

ive tried adding header files but it isn't working in dev-C++. please help

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <cmath>
void perm ( char*a , int l , int y )

{
int i ;
if (l== y)
printf("%",a);
else
{
for(i= l ; i<=y ; i+l)
{
     std::swap ((a+l) , (a+i));
perm (a, l+1,y);
std::swap ((a+l), (a+i)) ;
     }
   }
}
int main ()
{
char string [] ="hello" ;
int n = strlen (string);
perm ( s+0 , 0 , n-1);
return 0;
}

Explanation / Answer

#include <iostream>

using namespace std;

int perm(int n, int k)
{
int i;
int mult = 1;

for(i=0;i<=k-1;i++)
mult = mult*(n-i);

return mult;
}
int main ()
{
//test driver
if(perm(5,2)==20)
cout<<"Program working correctly ";

int n,k;
cout<<"Enter n::";
cin>>n;
cout<<"Enter k::";
cin>>k;

while(n>0&&k>0)
{
cout<<"No. of permutation= "<<perm(n,k);
cout<<" Enter next number (negative to quit) ";
cout<<"Enter n::";
cin>>n;
cout<<"Enter k::";
cin>>k;
}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote