Лямбда-выражение для подсчета кол-ва положительных и отрицательных чисел - C#
Формулировка задачи:
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.IO;
- namespace kozel
- {
- class Program
- {
- static void Main(string[] args)
- {
- int s = 0;
- int g = 0;
- Console.WriteLine("Введите число a");
- int a = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Введите число b");
- int b = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Введите число c");
- int c = Convert.ToInt32(Console.ReadLine());
- if (a < 0)
- ++s;
- if (b < 0)
- ++s;
- if (c < 0)
- ++s;
- else
- if (a > 0)
- ++g;
- if (b > 0)
- ++g;
- if (c > 0)
- ++g;
- Console.Write("Положительные числа:{0}", g);
- Console.Write("Отрицательные: {0}", s);
- Console.ReadLine();
- Console.ReadKey();
- }
- }
- }
Решение задачи: «Лямбда-выражение для подсчета кол-ва положительных и отрицательных чисел»
textual
Листинг программы
- List<int> list = new List<int>();
- Console.WriteLine("Введите число a");
- int a = Convert.ToInt32(Console.ReadLine());
- list.Add(a);
- Console.WriteLine("Введите число b");
- int b = Convert.ToInt32(Console.ReadLine());
- list.Add(b);
- Console.WriteLine("Введите число c");
- int c = Convert.ToInt32(Console.ReadLine());
- list.Add(c);
- Console.WriteLine("Положительныx чисeл: {0}", list.Count(n => n >= 0));
- Console.WriteLine("Отрицательныx чисел: {0}", list.Count(n => n < 0));
- Console.ReadKey();
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д