问题描述
对123三个数字进行全排列。
算法思想
123 132
213 231
312 321
C#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 数的全排列
{
class Program
{
static void Main(string[] args)
{
//123的全排列 123 132 213 231 312 321
Console.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();
}
}
}
运行结果