Q:

Write a C# program to compute the sum of all the elements of an array of integers

0

Write a C# program to compute the sum of all the elements of an array of integers

Sample Output:

Array1: [1, 2, 2, 3, 3, 4, 5, 6, 5, 7, 7, 7, 8, 8, 1]                  
Sum: 69

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class Exercise47
{  
   public static void Main() 
      {
         int[] nums = {1, 2, 2, 3, 3, 4, 5, 6, 5, 7, 7, 7, 8, 8, 1};
         Console.WriteLine("\nArray1: [{0}]", string.Join(", ", nums));
         var sum = 0;
            for (var i = 0; i < nums.Length; i++)
            {
                sum += nums[i];
            }
           Console.WriteLine("Sum: "+ sum);
    } 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now