Вариант C:
#include <stdio.h>
#define SIZE 10
int main(void)
{
float result = 1;
float array[SIZE];
for(int i = 0; i < SIZE; ++i)
{
scanf("%f", &array[i]);
if(array[i] > 0 && (i % 6 == 0))
{
result *= array[i];
}
}
printf("Произведение элементов, удовл. условию = %f", result);
return 0;
}
Вариант C++:
#include <iostream>
const int _size = 67;
int main()
{
float result = 1;
float arr[_size];
for(int i = 0; i < _size; ++i)
{
std::cin >> arr[i];
if(arr[i] > 0 && (i % 6 == 0))
{
result *= arr[i];
}
}
std::cout << "Результат = " << result;
return 0;
}
Объяснение:
Проверяем элемент. Если он больше нуля и стоит на позиции, кратной 6, то добавляем в общее произведение.
#include <array>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
int main()
{
std::array<int, 5> arr;
std::generate(arr.begin(), arr.end(), []()
{
return 1 + std::rand() % 100;
});
std::copy(arr.begin(), arr.end(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl << std::accumulate(arr.begin(), arr.end()-3, 0) << std::endl;
std::cout << std::accumulate(arr.begin(), arr.end()-2, 0) << std::endl;
std::cout << std::accumulate(arr.begin(), arr.end()-1, 0) << std::endl;
std::cout << std::accumulate(arr.begin(), arr.end(), 0) << std::endl;
}