can permutation and combination programming made in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

can permutation and combination programming made in c++

if there are six blank space and total digit is 9 .how many no can be made and what no.

20th Jan 2018, 6:09 AM
bhargav
bhargav - avatar
4 Answers
+ 20
//yes //btw here is the solution to your question(incomplete question) 👉if numbers can be repeated then 9^6 //no 0 as a digit 8.9^5//0 as a digit 👉if numbers can't be repeated then 9.8.7.6.5.4 //no 0 as a digit 8.8.7.6.5.4 //0 as a digit edit ::: understand the role of 0 //specify what digits if u want code , then try making it by your own first
20th Jan 2018, 6:24 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 9
C++'s standard library provided some good facilities to deal with statistical stuff. One of which is "std::next_permutation". As its name suggests you would be able to get the permutation of a bunch of elements. [http://en.cppreference.com/w/cpp/algorithm/next_permutation] Example: #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { // A list of 4 characters for our experiment vector<char> vChar = {'b', 'b', 'a', 'c'}; // before doing anything we need to sort our list sort(vChar.begin(), vChar.end()); // Let's get through our process while (next_permutation(vChar.begin(), vChar.end())) { for (const auto i : vChar) cout << i; cout << endl; } } Live link: [http://cpp.sh/9abtf] But, there's no "next_combination" thing in STL. The good news is, by tweaking the next_permutation algorithm you can reach your desired result for the last part of your question. Here is a good discussion about that matter: [https://stackoverflow.com/questions/9430568/generating-combinations-in-c]
20th Jan 2018, 7:45 AM
Babak
Babak - avatar
+ 4
you know code please answer
20th Jan 2018, 6:32 AM
bhargav
bhargav - avatar
+ 4
30th Sep 2019, 2:56 PM
MOHAN👨🏻‍💻
MOHAN👨🏻‍💻 - avatar