Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.
![](https://rs.olm.vn/images/avt/0.png?1311)
program TongSoChan;
var
n, i, x, tong: integer;
begin
write('Nhap so nguyen n: ');
readln(n);
tong := 0;
for i := 1 to n do
begin
read(x);
if x mod 2 = 0 then
tong := tong + x;
end;
writeln('Tong cac so chan la: ', tong);
readln;
end.
![](https://rs.olm.vn/images/avt/0.png?1311)
def xoa_phan_tu_chia_het_cho_3(arr):
return [x for x in arr if x % 3 != 0]
# Nhập số phần tử của dãy
n = int(input())
# Nhập dãy số nguyên
day_so = list(map(int, input().split()))
# Xóa các phần tử chia hết cho 3
ket_qua = xoa_phan_tu_chia_het_cho_3(day_so)
# In ra dãy sau khi xóa
print(*ket_qua)
![](https://rs.olm.vn/images/avt/0.png?1311)
# Dãy số thứ nhất
list1 = list(map(int, input("Nhập dãy số thứ nhất, cách nhau bằng khoảng trắng: ").split()))
so_chan1 = 0
so_le1 = 0
for num in list1:
if num % 2 == 0:
so_chan1 += 1
else:
so_le1 += 1
print("Trong dãy số thứ nhất có", so_chan1, "số chẵn và", so_le1, "số lẻ.")
# Dãy số thứ hai
list2 = list(map(int, input("Nhập dãy số thứ hai, cách nhau bằng khoảng trắng: ").split()))
so_chan2 = 0
so_le2 = 0
for num in list2:
if num % 2 == 0:
so_chan2 += 1
else:
so_le2 += 1
print("Trong dãy số thứ hai có", so_chan2, "số chẵn và", so_le2, "số lẻ.")
Mình đặt A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], bạn tham khảo nhé
1) Python:
def in_so_chan(A): so_chan = [x for x in A if x % 2 == 0] print("Các số chẵn:", so_chan) A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] in_so_chan(A)
2) Java import java.util.Arrays; import java.util.List; public class InSoChan { public static void inSoChan(List<Integer> A) { System.out.print("Các số chẵn: "); for (int x : A) { if (x % 2 == 0) { System.out.print(x + " "); } } System.out.println(); } public static void main(String[] args) { List<Integer> A = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); inSoChan(A); } }
3) C++
#include <iostream> #include <vector> using namespace std; void inSoChan(const vector<int>& A) { cout << "Các số chẵn: "; for (int x : A) { if (x % 2 == 0) { cout << x << " "; } } cout << endl; } int main() { vector<int> A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; inSoChan(A); return 0; }