Q:

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

0

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

Sample Output:

150
10

All Answers

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

using System;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        {
            Console.WriteLine(test(new[] { 10, 20, 30, 40, 50 }));
            Console.WriteLine(test(new[] { 10, 20, -30, -40, 50 })); 
        }     
       public static int  test(int[] a1)
          {
            return a1[0] + a1[1] + a1[2] + a1[3] + a1[4];
          } 
   }
} 

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