-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkod8_params.cs
More file actions
43 lines (33 loc) · 896 Bytes
/
kod8_params.cs
File metadata and controls
43 lines (33 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Linq;
using System.Collections.Generic;
namespace HelloWorld;
/*Условие:
C# PrintSum(params int[] numbers)
Выводит: "Сумма чисел: X" (или "Нет чисел", если пусто или null)
Примеры вызова:
PrintSum(1, 2, 3) → Сумма чисел: 6
PrintSum() → Нет чисел
PrintSum(10) → Сумма чисел: 10
Напиши метод + 4–5 вызовов в Main.*/
public static class Program
{
static void PrintSum(params int[] numbers)
{
if (numbers == null || numbers.Length = 0)
{
return;
}
int summ = 0;
foreach (int i in numbers)
{
summ += i;
}
Console.WriteLine(summ);
}
public static void Main()
{
PrintSum(1, 2, 3);
PrintSum();
PrintSum(3);
}