Question: Please Help!!! Write a C++ program: Question:- There are 120 permutations of the numbers 1, 2, 3,... Please Help!!! Write a C++ program: Question:- There

Please Help!!! Write a C++ program: Question:- There are 120 permutations of the numbers 1, 2, 3,...

Please Help!!!

Write a C++ program: Question:- There are 120 permutations of the numbers 1, 2, 3, 4, and 5 (5! or 5 factorial). Generate and classify each permutation by its sky number and display all the permutations whose sky number is 4. The sky number is a number from 1 to 5 that represents the number of array elements in the permutation that are greater than the greatest previous element. Let {2, 3, 1, 4, 5} be a permutation. Its sky number is 4 because, from the left to the right:

2 is greater than any previous number

3 is greater than any previous number

4 is greater than any previous number

5 is greater than any previous number

Any permutation beginning with the number 5 has a sky number of 1. The name comes from the idea that the numbers represent the stories in a multistory building. For the permutation {2, 3, 1, 4, 5}, this can be pictured as

X

XX

X XX

XX XX

XX XXX

so looking from the left to the right, you see the tops of 4 buildings.

Define a two-dimensional array permute[120][5] with 120 rows and 5 columns. Generate each permutation into a row of the array. Since there are 120 permutations, this will fill the array. Then make a pass through the rows of the array calculating each sky number. Display each permutation that has a sky number of 4. Your output should look like:

1, 2, 3, 5, 4 has a sky number of 4

1, 2, 4, 3, 5 has a sky number of 4

1, 2, 4, 5, 3 has a sky number of 4

1, 3, 2, 4, 5 has a sky number of 4

1, 3, 4, 2, 5 has a sky number of 4

1, 3, 4, 5, 2 has a sky number of 4

2, 1, 3, 4, 5 has a sky number of 4

2, 3, 4, 1, 5 has a sky number of 4

2, 3, 4, 5, 1 has a sky number of 4

there are 10 permutations with sky number 4

--The coding that I have so far ---

static int permute() { const int MAX = 4; int ix, jx, kx, lx; for (ix = 1; ix => { for (jx = 1; jx => { if (jx == ix) continue; for (kx = 1; kx => { if (kx == ix || kx == jx) continue; for (lx = 1; lx => { if (lx == ix || lx == jx || lx == kx) continue;

std::cout } } } }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!