C#数的全排列
問題描述
對123三個數(shù)字進(jìn)行全排列。
算法思想
123 132
213 231
312 321
C#代碼
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace 數(shù)的全排列 {class Program{static void Main(string[] args){//123的全排列 123 132 213 231 312 321Console.WriteLine("123的全排列是:");for (int i = 1; i < 4; i++){for (int j = 1; j < 4; j++){for (int m = 1; m < 4; m++){if ((m != i) && (m != j) && (i != j)){Console.Write(i);Console.Write(j);Console.Write(m);Console.Write(" ");}} }Console.WriteLine();}Console.ReadKey();}} }運(yùn)行結(jié)果
總結(jié)
- 上一篇: 静远(诗一首)
- 下一篇: C#深度优先做数字的全排列