current position:Home>Output the full arrangement of all 1 2 3 4 5 in dictionary order

Output the full arrangement of all 1 2 3 4 5 in dictionary order

2022-02-02 11:39:56 CSDN Q & A

No input , Output all... In dictionary order 1 2 3 4 5 The whole arrangement .
I hope not to use recursion , Recursion won't !




Refer to the answer 1:
#include <stdio.h>const int N = 5;int h[6];int main() {    int i, j, k, l, m;        for(i = 1; i <= N; ++i) {        h[i] = 1;                                // (1)         for(j = 1; j <= N; ++j) {            if(h[j]) continue;                   // (2)            h[j] = 1;            for(k = 1; k <= N; ++k) {                if(h[k]) continue;               // (3)                h[k] = 1;                for(l = 1; l <= N; ++l) {                    if(h[l]) continue;           // (4)                    h[l] = 1;                     for(m = 1; m <= N; ++m) {                          if(h[m]) continue;     // (5)                          printf("%d%d%d%d%d\n", i, j, k, l, m);                    }                    h[l] = 0;                    // (6)                }                h[k] = 0;                        // (7)            }            h[j] = 0;                            // (8)        }        h[i] = 0;                                // (9)    }    return 0;}
  • $(1)(2)(3)(4)(5)$ Stands for mark ;
  • $(6)(7)(8)(9)$ The representative flag is empty ;

Extended reading




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202021139546045.html

Random recommended