[求助]求算法
2个数组x={0,0,0,0,0}
y={1,2,3,4,5,}
把y中的5个数随机放到x中,x中的元素不能重复。
2005-04-11 16:32
2005-04-11 17:04
2005-04-11 17:09
using System;
namespace ConsoleApplication16 { /// <summary> /// Class1 的摘要说明。 /// </summary> class Class1 { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) { int[] y= new int[10]; y[0] = 10; int j=0; while(j<10) { Random r = new Random(); int x = r.Next(0,10); int n = 0; for (int i=0;i<j;i++) { if (y[i]==x) n++; } if (n==0) { y[j]=x; Console.WriteLine("{0},{1}",j,y[j]); j++; } Console.ReadLine(); } } } } 唉!没人帮忙,自己做出来了!供大家参考

2005-04-11 23:27
2005-04-11 23:28
2005-04-11 23:37
2005-04-12 08:28

2005-04-12 11:26
2005-04-12 11:34
2005-04-12 12:16