'1. Сформировать одномерный массив из восьми вещественных значений. Dim M(8) As Single, i As Integer, s As String For i = 1 To 8 M(i) = Rnd * 20 - 10 s = s + CStr(M(i)) + " " Next MsgBox s
'2. Сформировать двумерный массив из А строк и В столбцов. Dim M() As Single, i As Integer, j As Integer, A As Integer, B As Integer, s As String A = 3 B = 5 ReDim M(A, B) For i = 1 To A For j = 1 To B M(i, j) = Rnd * 20 + 2 s = s + CStr(M(i, j)) + " " Next s = s + vbCrLf Next MsgBox s
'3. Составить программу для определения максимального и минимального элементов двумерного массива. Dim M() As Single, i As Integer, j As Integer, A As Integer, B As Integer, s As String Dim Min As Single, Max As Single A = 3: B = 5 Min = 100: Max = 0 ReDim M(A, B) For i = 1 To A For j = 1 To B M(i, j) = Rnd * 20 + 2 s = s + CStr(M(i, j)) + " " If Max < M(i, j) Then Max = M(i, j) If Min > M(i, j) Then Min = M(i, j) Next s = s + vbCrLf Next s = s + "Max = " & Max & vbCrLf s = s + "Min = " & Min & vbCrLf MsgBox s
'4. Сформировать одномерный массив из 10 целых элементов. Найти сумму положительных и четных элементов массива. Dim M(10) As Integer, i As Integer, sum As Integer, s As String, s1 As String For i = 1 To 10 M(i) = Rnd * 20 - 10 s = s + CStr(M(i)) + " " If (M(i) > 0) And (M(i) Mod 2 = 0) Then s1 = s1 + CStr(M(i)) + " ": sum = sum + M(i) Next s = s + vbCrLf s = s + s1 + vbCrLf s = s + "sum = " & sum MsgBox s
Форматированный код на C# и демонстрация работы на скриншотах.
Код текстом ниже.
using System;
using System.Linq;
namespace task29989793
{
class Program
{
static void Main()
{
Console.Write("Enter number: ");
var number = Console.ReadLine().Select(i => int.Parse(i.ToString()));
Console.WriteLine($"Count of odd digits: {number.Count(i => i % 2 == 1)}");
Console.WriteLine($"Count of even digits: {number.Count(i => i % 2 == 0)}");
}
}
}
Dim M(8) As Single, i As Integer, s As String
For i = 1 To 8
M(i) = Rnd * 20 - 10
s = s + CStr(M(i)) + " "
Next
MsgBox s
'2. Сформировать двумерный массив из А строк и В столбцов.
Dim M() As Single, i As Integer, j As Integer, A As Integer, B As Integer, s As String
A = 3
B = 5
ReDim M(A, B)
For i = 1 To A
For j = 1 To B
M(i, j) = Rnd * 20 + 2
s = s + CStr(M(i, j)) + " "
Next
s = s + vbCrLf
Next
MsgBox s
'3. Составить программу для определения максимального и минимального элементов двумерного массива.
Dim M() As Single, i As Integer, j As Integer, A As Integer, B As Integer, s As String
Dim Min As Single, Max As Single
A = 3: B = 5
Min = 100: Max = 0
ReDim M(A, B)
For i = 1 To A
For j = 1 To B
M(i, j) = Rnd * 20 + 2
s = s + CStr(M(i, j)) + " "
If Max < M(i, j) Then Max = M(i, j)
If Min > M(i, j) Then Min = M(i, j)
Next
s = s + vbCrLf
Next
s = s + "Max = " & Max & vbCrLf
s = s + "Min = " & Min & vbCrLf
MsgBox s
'4. Сформировать одномерный массив из 10 целых элементов. Найти сумму положительных и четных элементов массива.
Dim M(10) As Integer, i As Integer, sum As Integer, s As String, s1 As String
For i = 1 To 10
M(i) = Rnd * 20 - 10
s = s + CStr(M(i)) + " "
If (M(i) > 0) And (M(i) Mod 2 = 0) Then s1 = s1 + CStr(M(i)) + " ": sum = sum + M(i)
Next
s = s + vbCrLf
s = s + s1 + vbCrLf
s = s + "sum = " & sum
MsgBox s