-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
82 lines (68 loc) · 1.88 KB
/
Copy pathProgram.cs
File metadata and controls
82 lines (68 loc) · 1.88 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//Напишите цикл, который принимает на вход два числа (A и B) и возводит число A в натуральную степень B.
/*
int Stepen(int number, int stepen)
{
int res = number;
for (int i = 1; i < stepen; i++)
{
res *= number;
}
return res;
}
int InputNum(string message)
{
Console.Write(message);
return int.Parse(Console.ReadLine()!);
}
int num = InputNum("Введите целое число: ");
int step = InputNum("Введите степень числа: ");
int result = Stepen(num, step);
Console.WriteLine($"Степень числа {num} равна {result}.");
*/
//Напишите программу, которая принимает на вход число и выдаёт сумму цифр в числе.
/*
int InputNum(string message)
{
Console.Write(message);
return int.Parse(Console.ReadLine()!);
}
int Sum(int num)
{
int res = 0;
while (num != 0)
{
res += num % 10;
num /= 10;
}
return res;
}
int num = InputNum("Введите целое число: ");
int result = Sum(num);
Console.WriteLine($"Сумма цифр числа {num} равна {result}.");
*/
//Напишите программу, которая задаёт массив из 8 элементов и выводит их на экран.
int InputNum(string message)
{
Console.Write(message);
return int.Parse(Console.ReadLine()!);
}
int[] ArrayRand(int size)
{
int[] array = new int[size];
for (int i = 0; i < size; i++)
{
array[i] = new Random().Next(100);
}
return array;
}
void PrintArray(int[] array)
{
int size = array.Length;
for (int i = 0; i < size; i++)
{
Console.Write(array[i] + " ");
}
}
int len = InputNum("Введите длину массива: ");
int[] arr = ArrayRand(len);
PrintArray(arr);