Предмет: Информатика, автор: aisha08102020

Дан массив, состоящий из целых чисел. Нумерация элементов начинается с 0. Напишите программу, которая выведет элементы массива, номера которых четны (0, 2, 4...). Сначала задано число — количество элементов в массиве. Далее через пробел записаны чисел — элементы массива. Массив состоит из целых чисел. Необходимо вывести все элементы массива с чётными номерами. Необходимо вывести все четные элементы массива (то есть те элементы, которые являются четными числами).

С++


aisha08102020: #include
using namespace std;
int main() {
int n;
cin>>n;
int a[n];

for(int i=0; i cin>>a[i];
if(a[i]%2==0) {
cout< }
}

return 0;
}

Ответы

Автор ответа: forellka
0
Пример кода на C++ для решения данной задачи:

#include

using namespace std;

int main() {
int n;
cin >> n; // считываем количество элементов массива
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i]; // считываем элементы массива
}
for (int i = 0; i < n; i += 2) {
if (arr[i] % 2 == 0) {
cout << arr[i] << " "; // выводим четные элементы с четными индексами
}
}
return 0;
}

Пример входных данных:
5
1 2 3 4 5

Пример выходных данных:
1 3 5 (так как четными индексами являются 0, 2, 4, а четными числами только 2 и 4)

aisha08102020: выводится только как пустой результат , в коде где то ошибка
forellka: У меня выводит четные числа
Похожие вопросы
Предмет: Английский язык, автор: pavlikkolchin9
Надо определить о чем написан текст(даю 30 баллов)

1) popular exercise;
2) the weather;
3) traditional food;
4) health advice;
5) an animal;
6) a place to visit.

A) The beluga whale lives in the Arctic. They can dive more than 3,100 feet deep looking for food. They eat fish, mainly cod. Beluga whales live in groups. Usually there are ten individuals, and they live and feed together. In Russia, the whales generally live in the waters that border the north of the country. The whales migrate according to the seasons.

B) You should go to the zoo if you want to see animals with your own eyes. There you can learn about what they eat, their habits, environment, and all sorts of other interesting facts about animals. Another name for a zoo is a zoological garden. Today many zoos do wonderful work in animal research and take great care of their animals. Many animals feel at home there.

C) September and October are wonderful months in Canada, as most days are cool, crisp and pleasant. The Canadian winters are cold and long, and in the northern parts of the country they can be severe. In the central part the daily average temperatures are about -20 °Celsius. In these regions, snow can cover the ground almost six months of the year.

D) Japanese cuisine is very popular around the world and for good reason. It has a good balance of ingredients. Centuries before Japanese people were eating sushi, they first enjoyed raw fish without the rice. The name «sashimi» means any thinly sliced raw food, including raw beef and chicken. However fish and seafood are the most popular types of this dish.

E) To eat well and best prepare for your training, it is always smart to eat a nice breakfast. If you don't eat at all before exercising, you could feel weak. If you are going to eat a big breakfast, eat it at least three hours before exercising. If you only have two hours before your game, eat a smaller portion. You also need to eat some food after you exercise to help your muscles recover.
Предмет: Литература, автор: sofiavitkovska19