美文网首页
随机对一个长度为100的一维数组赋值,用do while求出每1

随机对一个长度为100的一维数组赋值,用do while求出每1

作者: 唯一的one | 来源:发表于2018-11-29 19:58 被阅读0次
image.png
image.png
Random random = new Random();
            int[] arrs = new int[100];
            int index = 0;
            int sum = 0;
            do
            {
                arrs[index] = random.Next(0, 1000);
                Console.WriteLine(arrs[index]);
                sum += arrs[index];
                if ((index + 1) % 10 == 0)
                {
                    Console.WriteLine("sum= " + sum);
                    sum = 0;
                }
                index++;
            } while (index < arrs.Length);

相关文章

网友评论

      本文标题:随机对一个长度为100的一维数组赋值,用do while求出每1

      本文链接:https://www.haomeiwen.com/subject/nlcqcqtx.html