
Составьте программу, которая заполняет массив б(1..10) случайными целыми числами в диапазоне от 1
до 10 и находит количество пар элементов с чётными значениями пример вывода Исходный массив : 10 2 4 1 3 5 7 8 количество пар чётных элементов = 2

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

#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");
}



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!


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







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