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.
uses crt;
var a:array[1..100]of integer;
i,n,k,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
write('Nhap k='); readln(k);
t:=0;
for i:=1 to n do
if a[i] mod k=0 then t:=t+a[i];
writeln(t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,tc,tl,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
tc:=0;
tl:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then tc:=tc+a[i]
else tl:=tl+a[i];
end;
writeln('Tong cac so chan la: ',tc);
writeln('Tong cac so le la: ',tl);
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day so la: ',t);
readln;
end.
uses crt;
var a:array[1..1000]of integer;
i,n,dem1,dem2,t1,dem3,j,kt:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
readln(a[i]);
dem1:=0;
dem2:=0;
t1:=0;
for i:=1 to n do
begin
if a[i] mod 2=0 then
begin
dem1:=dem1+1;
t1:=t1+a[i];
end;
else dem2:=dem2+1;
end;
dem3:=0;
for i:=1 to n do
if (a[i]>1) then
begin
kt:=0;
for j:=2 to trunc(sqrt(a[i])) do
if a[i] mod j=0 then kt:=1;
if kt=0 then dem3:=dem3+1;
end;
writeln(dem1, ' ',dem2);
writeln(t1);
writeln(dem3);
readln;
end.
program BaiToanMang;
var
A: array[1..100] of integer;
N, i, demChan, tongLeChia3: integer;
begin
write('Nhap so phan tu cua mang: ');
readln(N);
writeln('Nhap cac phan tu cua mang: ');
for i := 1 to N do
begin
write('a[', i, ']= ');
readln(A[i]);
end;
tongLeChia3 := 0;
for i := 1 to N do
begin
if (A[i] mod 2 = 1) and (A[i] mod 3 = 0) then
begin
tongLeChia3 := tongLeChia3 + A[i];
end;
end;
writeln('Tong cac so le chia het cho 3: ', tongLeChia3);
demChan := 0;
for i := 2 to N do
begin
if (A[i] mod 2 = 0) and (i mod 2 = 1) then
begin
demChan := demChan + 1;
end;
end;
writeln('So phan tu chan o vi tri le: ', demChan);
writeln('Cac so chan chia het cho 5: ');
for i := 1 to N do
begin
if (A[i] mod 2 = 0) and (A[i] mod 5 = 0) then
begin
write(A[i], ' ');
end;
end;
end.
ko bt đúng ko ko dùng pascal nhiều
#include <bits/stdc++.h>
using namespace std;
long long n,i,x,dem,t;
int main()
{
cin>>n;
dem=0;
t=0;
for (i=1; i<=n; i++)
{
cin>>x;
if (x%3==0)
{
dem++;
t+=x;
}
}
cout<<dem<<" "<<t;
return 0;
}