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

2018-11-29  本文已影响0人  唯一的one
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);
上一篇 下一篇

猜你喜欢

热点阅读