fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define N 15
  6. char *s, *w;
  7. int n;
  8.  
  9. void
  10. placement(int x)
  11. {
  12. int i;
  13. char t;
  14.  
  15. if (x == 0) {
  16. for(i=0; i<n-1; i++) {
  17. printf("%c,", w[i]);
  18. }
  19. printf("%c\n", w[i]);
  20. return;
  21. }
  22. for (i = n; i; i--) {
  23. if (s[i - 1] == ' ')
  24. continue;
  25. w[x - 1] = s[i - 1];
  26. t = s[i - 1];
  27. s[i - 1] = ' ';
  28. placement(x - 1);
  29. s[i - 1] = t;
  30. }
  31. }
  32.  
  33. int
  34. main(int argc, char **argv)
  35. {
  36. n = atoi(argv[1]);
  37. s = malloc(sizeof(char) * (N + 1));
  38. strncpy(s, "abcdefghijklmno", n);
  39. w = malloc(sizeof(char) * (N + 1));
  40. strcpy(w, s);
  41. placement(n);
  42.  
  43. return 0;
  44. }
Runtime error #stdin #stdout 0.02s 1716KB
stdin
Standard input is empty
stdout
Standard output is empty