1) если нужно найти произведение элементов с нечетными индексами:
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
signed main() {
int a[20];
srand(time(NULL));
for(int i = 0; i < 20; i++)
a[i] = rand()%46 - 19;
for(auto i: a)
cout << i << " ";
cout << "\n";
long long ans = 1;
for(int i = 0; i < 20; i++)
if(i % 2 == 1)
ans *= a[i];
cout << ans;
}
2) Если нужно найти произведение элементов с нечетными порядковыми номерами:
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
signed main() {
int a[20];
srand(time(NULL));
for(int i = 0; i < 20; i++)
a[i] = rand()%46 - 19;
for(auto i: a)
cout << i << " ";
cout << "\n";
long long ans = 1;
for(int i = 0; i < 20; i++)
if((i+1) % 2 == 1)
ans *= a[i];
cout << ans;
}
var
a: array[1..n] of integer;
i, k: integer;
begin
//считываем массив
for i:=1 to n do
readln(a[i]);
k:=0;
//проверяем каждый элемент
//если он <= 3, то выводим
//на экран элемент и индекс,
//и увеличиваем k на 1
for i:=1 to n do
if a[i] <= 3 then
begin
writeln('Элемент массива: ', a[i], ' Индекс: ', i);
inc(k);
end;
writeln('Количество элеметнов: ', k);
end.