Write a C# Sharp program to calculate the sum of two lowest negative numbers of a given array of integers
- برمجة سي شارب
- برمجة
- 2021-05-29
- ahmadghneem
الأجوبة
using System;
using System.Linq;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
int[] nums = { -10, -11, -12, -13, -14, 15, 16, 17, 18, 19, 20 };
Console.WriteLine("Original array elements:");
for (int i = 0; i < nums.Length; i++)
{
Console.Write(nums[i] + " ");
}
Console.WriteLine("\nSum of two lowest negative numbers of the said array of integers: " + test(nums));
int[] nums1 = { -1, -2, -4, 0, 3, 4 , 5, 9 };
Console.WriteLine("\nOriginal array elements:");
for (int i = 0; i < nums1.Length; i++)
{
Console.Write(nums1[i] + " ");
}
Console.WriteLine("\nSum of two lowest negative numbers of the said array of integers: " + test(nums1));
}
public static int test(int[] values)
{
return values.Where(x => x < 0).OrderBy(x => x).Take(2).Sum();
}
}
}أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال