Xxxmara
11.05.2022 04:52

Дан массив А из 10 целых чисел. Создать новый массив В из номеров четных эле-ментов массива А.(программка должна работать в Visual Basic)
Не понимаю почему вылазит ошибка в строке( B(j)=i )
Dim i, j, B, A(1 To 20) As Integer
For i = 1 To 20
A(i) = Int(Rnd() * 5)
Next i
For i = 1 To 20
Cells(22, i + 1) = A(i)
Next i
j = 1
For i = 1 To 20
If A(i) Mod 2 = 0 Then
j = j + 1
B(j) = i
End If
Next i
For i = 1 To 20
Cells(24, i + 1) = B(j)
Next i

Нажмите на рекламу ниже и сразу увидите ответ
Популярные вопросы:
Ответ:
Dffc
08.02.2023 02:32
/* gnu gcc */
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
int x[10];
int y[20];
int z[25];

int xs=0, ys=0, zs=0;
// Заполняем массивы случайными числами до 100
srand(time(0));
cout <<"Массив X(10):" <<endl;
for(int i=0; i<10; ++i)
{
x[i] = rand() % 100;
cout <<x[i] <<" ";
}
cout <<endl;
cout <<"Массив Y(20):" <<endl;
for(int i=0; i<20; ++i)
{
y[i] = rand() % 100;
cout <<y[i] <<" ";
}
cout <<endl;
cout <<"Массив Z(25):" <<endl;
for(int i=0; i<25; ++i)
{
z[i] = rand() % 100;
cout <<z[i] <<" ";
}
cout <<endl;

// Считаем суммы элементов массивов
for(int i=0; i<10; ++i)
xs+=x[i];
for(int i=0; i<20; ++i)
ys+=y[i];
for(int i=0; i<25; ++i)
zs+=z[i];
cout <<endl;

// Выводим суммы элементов на экран
cout <<"Сумма элементов массива X(10) = " <<xs <<endl;
cout <<"Сумма элементов массива Y(20) = " <<ys <<endl;
cout <<"Сумма элементов массива Z(25) = " <<zs <<endl;

return 0;
}

6. вычислить суммы элементов, для массивов х(10), y(20), z(25).
0,0(0 оценок)
Ответ:
AcidSmile
02.03.2023 08:22
Несколько вариантов:
program StrToInt;
uses crt;
var
st : string;
num : integer;

function val1 (s : string) : integer;
var
i, res : integer;
s1 : string;

begin
s1 := '';
res := 0;
for i:=1 to length(s) do
case s[i] of
'0' : s1 := s1+'0';
'1' : s1 := s1+'1';
'2' : s1 := s1+'2';
'3' : s1 := s1+'3';
'4' : s1 := s1+'4';
'5' : s1 := s1+'5';
'6' : s1 := s1+'6';
'7' : s1 := s1+'7';
'8' : s1 := s1+'8';
'9' : s1 := s1+'9';
end;
val (s1, res);
if s[1]='-' then res := res * -1;
val1 := res;
end;

function isnumber (ch : char) : boolean;
var res : boolean;
begin
res := false;
case ch of
'0' : res := true;
'1' : res := true;
'2' : res := true;
'3' : res := true;
'4' : res := true;
'5' : res := true;
'6' : res := true;
'7' : res := true;
'8' : res := true;
'9' : res := true;
end;
isnumber := res;
end;

function val2 (s : string) : integer;
var
i, res : integer;

begin
res := 0;
for i:=1 to length(s) do begin
if isnumber(s[i]) then res := res*10 + byte(s[i])-byte('0');
end;

val2 := res;
end;

BEGIN
write('Input a string: ');
readln(st);
val(st, num);
writeln('Standart function: ', num);
num := val1(st);
writeln('Function VAL1: ', num);
num := val2(st);
writeln('Function VAL2: ', num);

END.
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота