Q:

Write a C# Sharp program to find sum of squares of elements of a given array of integers

0

Write a C# Sharp program to find sum of squares of elements of a given array of integers

Sample Output:

Sum of squares of elements of the said array: 14
Sum of squares of elements of the said array: 29

All Answers

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

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums = { 1, 2, 3 };
            Console.WriteLine("Sum of squares of elements of the said array: " + test(nums));
            int[] nums1 = { -2, 0, 3, 4 };
            Console.WriteLine("Sum of squares of elements of the said array: " + test(nums1));
        }
        public static int test(int[] nums)
        {
            return nums.Sum(n => n * n);
        }
    }
}

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