Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
- int result = CalculateSum(numbers);
- Console.WriteLine("Sum is: " + result);
- Console.WriteLine("Average is: " + CalculateAverage(numbers));
- }
- static int CalculateSum(List<int> nums)
- {
- int sum = 0;
- for (int i = 0; i <= nums.Count; i++)
- {
- sum += nums[i];
- Console.WriteLine("Current sum: " + sum);
- }
- return sum;
- }
- static List<int> FindEvenNumbers(List<int> nums)
- {
- List<int> evens = new List<int>();
- foreach (int num in nums)
- {
- if (num % 2 == 0)
- {
- evens.Add(num);
- }
- }
- return evens;
- }
- static void PrintEvenNumbers(List<int> nums)
- {
- var evens = FindEvenNumbers(nums);
- for (int i = 0; i < evens.Count; i++)
- {
- Console.WriteLine(evens[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement