Вопрос задан 18.02.2019 в 19:31. Предмет Информатика. Спрашивает Всеволодов Никодим.

Составьте программу, которая заполняет массив б(1..10) случайными целыми числами в диапазоне от 1

до 10 и находит количество пар элементов с чётными значениями пример вывода Исходный массив : 10 2 4 1 3 5 7 8 количество пар чётных элементов = 2
0 0
Перейти к ответам

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

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

#include <iostream>

 

int main()

{

 int b[10];

 for(int i=0;i<10;i++)

 { 

  b[i]=rand()%10+1;

 }

 int a=0;

 for(int i=0;i<9;i++)

 {

  if(b[i]%2==0 && b[i+1]%2==0)

   a++;

 }

std::cout<<"Чётных пар: "<<a<<std::endl;

system("PAUSE");

}

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

Program to Fill an Array and Find the Number of Pairs with Even Values

To accomplish this task, we can use Python to create a program that fills an array with random integers and then calculates the number of pairs with even values.

Here's a Python program to achieve this:

```python import random

# Fill the array with random integers in the range from 1 to 10 array = [random.randint(1, 10) for _ in range(10)]

# Count the number of pairs with even values count = sum(1 for i in range(len(array)-1) if array[i] % 2 == 0 and array[i+1] % 2 == 0)

# Output the original array and the count of pairs with even values print("Original array:", array) print("Number of pairs with even elements:", count) ```

When you run this program, it will output the original array filled with random integers and the count of pairs with even values.

This program uses the `random` module to generate random integers and a list comprehension to fill the array. Then, it iterates through the array to count the number of pairs with even values.

This program provides a simple and efficient way to achieve the desired outcome.

Let me know if you need further assistance with this program!

0 0

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

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

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