Advertisement
damesova

Работа с чужд код - анализ

Jan 14th, 2025
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
  9.         int result = CalculateSum(numbers);
  10.         Console.WriteLine("Sum is: " + result);
  11.  
  12.         Console.WriteLine("Average is: " + CalculateAverage(numbers));
  13.     }
  14.  
  15.     static int CalculateSum(List<int> nums)
  16.     {
  17.         int sum = 0;
  18.         for (int i = 0; i <= nums.Count; i++)
  19.         {
  20.             sum += nums[i];
  21.             Console.WriteLine("Current sum: " + sum);
  22.         }
  23.         return sum;
  24.     }
  25.  
  26.     static List<int> FindEvenNumbers(List<int> nums)
  27.     {
  28.         List<int> evens = new List<int>();
  29.         foreach (int num in nums)
  30.         {
  31.             if (num % 2 == 0)
  32.             {
  33.                 evens.Add(num);
  34.             }
  35.         }
  36.         return evens;
  37.     }
  38.  
  39.     static void PrintEvenNumbers(List<int> nums)
  40.     {
  41.         var evens = FindEvenNumbers(nums);
  42.         for (int i = 0; i < evens.Count; i++)
  43.         {
  44.             Console.WriteLine(evens[i]);
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement