Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace SumEvenNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] num = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- int sum = 0;
- for (int i = 0; i < num.Length; i++)
- {
- int current = num [i];
- if (current % 2 == 0)
- {
- sum += current;
- }
- }
- Console.WriteLine(sum);
- }
- }
- }
- Pешение с LINQ:
- using System;
- using System.Linq;
- namespace SumEvenNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] num = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .Where( a => a % 2 == 0)
- .ToArray();
- Console.WriteLine(num.Sum());
- }
- }
- }
- ИЛИ :
- using System;
- using System.Linq;
- namespace SumEvenNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Where(a => a % 2 == 0).Sum());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement