For each element in the array,which is filled with random integers, I need to add value of previous element to it's current element.
This is my code:
class Program
{
static void Main(string[] args)
{
int[] numbers = new int[10];
Random generator = new Random();
for (int i = 0; i < numbers.Length; i++)
{
numbers[i] = generator.Next(0, 100);
}
for (int i = 0; i < numbers.Length; i++)
{
Console.Write("{0} ", numbers[i]);
}
Console.WriteLine();
for (int i = 0; i < numbers.Length+1; i++)
{
Console.Write("{0} ", numbers[i]);
numbers[i + 1] += numbers[i];
}
Aucun commentaire:
Enregistrer un commentaire