Вопрос задан 06.11.2023 в 09:37. Предмет Информатика. Спрашивает Кузьмина Злата.

Помогите пожалуйста с информатикой. Составить программу на языке си: Дан вещественный массив,

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

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Смирнов Евгений.

Ответ:

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

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос