Question: Write a C++ program that, for a given n and k, outputs all the permutations which can be created using k out of n digits.
Write a C++ program that, for a given n and k, outputs all the permutations which can be created using k out of n digits. For example, if n = 4 and k = 3, your program should output: 012 013 021 023 031 032 102 103 . . . 321 (24 in total). Output all permutations to the console separated by a single space character. Your program should in theory work for each positive n. Due to the output size, however, you should expect an extreme long runtime for any n > 10.
Your program should be in a single file permutations.cpp. The numbers n and k are given as command line parameters when your program is started. You can determine n and k using the following code.
int main(int argc, char* argv[]) { int n = atoi(argv[1]); int k = atoi(argv[2]); /* ... */ return 0; } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
