daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. #define SIZE 4
  5.  
  6. void printVariationsWithRepetitions(char * arr, std::string variation, int size, int length)
  7. {
  8.     if (length == 0)
  9.     {
  10.         std::cout << variation << '\n';
  11.         return;
  12.     }
  13.  
  14.  
  15.     for (int i = 0; i < size; ++i)
  16.     {
  17.         std::string newVariation;
  18.         newVariation = variation + arr[i];
  19.         printVariationsWithRepetitions(arr, newVariation, size, length - 1);
  20.     }
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26.     char arrayOfLetters[SIZE] = { 'A','B','C','D' };
  27.     int length = 3;
  28.     printVariationsWithRepetitions(arrayOfLetters, "", SIZE, length);
  29.  
  30.  
  31.  
  32.     return 0;
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top