1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace SumTwoSmallestNumber
7{
8 class Program
9 {
10 //SumSmallest([19, 5, 42, 2, 77]) ➞ 7
11 //SumSmallest([10, 343445353, 3453445, 3453545353453]) ➞ 3453455
12 //SumSmallest([2, 9, 6, -1]) ➞ 8
13 //SumSmallest([879, 953, 694, -847, 342, 221, -91, -723, 791, -587]) ➞ 563
14 //SumSmallest([3683, 2902, 3951, -475, 1617, -2385]) ➞ 4519
15 public static int SumSmallest(List<int> lstNumber)
16 {
17 return lstNumber.Where(z => z > 0).OrderBy(z => z).Take(2).Sum();
18 }
19
20 static void Main(string[] args)
21 {
22 List<int> lstNumber = new List<int>();
23 bool isContinue = true;
24 do
25 {
26 Console.Write("Input number (enter N for quit): ");
27 string input = Console.ReadLine();
28 if(input == "N")
29 {
30 isContinue = false;
31 break;
32 }
33
34 int numberInput = Convert.ToInt32(input);
35 lstNumber.Add(numberInput);
36 } while (isContinue);
37
38 Console.WriteLine("Sum of Two smallest number is: {0}", SumSmallest(lstNumber));
39
40 Console.ReadKey();
41 }
42 }
43}