
Помогите пожалуйста с информатикой. Составить программу на языке си: Дан вещественный массив,
состоящий из 67 элементов. Найти произведение положительных элементов, у которых порядковый номер элемента кратен 6. (Нумерация элементов массива начинается с нуля).

Ответы на вопрос

Ответ:
Вариант 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, то добавляем в общее произведение.



Program to Find the Product of Positive Elements at Positions Divisible by 6 in a Real Array
To solve this problem, you can write a program in the C programming language. Here's an example program that finds the product of positive elements in a real array at positions divisible by 6:
```c
#include
int main() { float array[67]; // Declare the array with 67 elements int i; float product = 1.0; // Initialize the product to 1.0
// Input the array elements printf("Enter the elements of the array:\n"); for (i = 0; i < 67; i++) { printf("Element %d: ", i); scanf("%f", &array[i]); }
// Calculate the product of positive elements at positions divisible by 6 for (i = 0; i < 67; i += 6) { if (array[i] > 0) { product *= array[i]; } }
// Output the result printf("The product of positive elements at positions divisible by 6 is: %.2f\n", product);
return 0; } ```
In this program, we declare a float array with 67 elements. We then use a loop to input the elements of the array from the user. After that, we iterate over the array using a loop with a step size of 6 to access the elements at positions divisible by 6. If the element is positive, we multiply it with the current product. Finally, we output the product of the positive elements at positions divisible by 6.
Please note that this program assumes that the user will input valid floating-point numbers for the array elements. You can modify the program to add error handling and input validation if needed.
I hope this helps! Let me know if you have any further questions.


Похожие вопросы
Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili