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.
#include <bits/stdc++.h>
using namespace std;
long long a[6],i,t,t1;
int main()
{
t=0;
for (i=1; i<=n; i++)
{
cin>>a[i];
if (a[i]%2==0) t=t+a[i];
}
t1=0;
for (i=1; i<=n; i++)
if ((a[i]%2!=0) and (i%2==0)) t1=t1+a[i];
cout<<t<<endl;
cout<<t1;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
long long a[10000],i,n,t1,t2,dem1,dem2;
int main()
{
cin>>n;
for (i=1; i<=n; i++)
cin>>a[i];
dem1=0;
dem2=0;
t1=0;
t2=0;
for (i=1; i<=n; i++)
{
if (a[i]>0)
{
dem1++;
t1+=a[i];
}
if (a[i]<0)
{
dem2++;
t2+=a[i];
}
}
long long t3=0;
for (i=1; i<=n; i++)
if (i%2==1) t3+=a[i];
long long t4=0;
for (i=1; i<=n; i++)
if (i%2==1 && a[i]%2==0) t4+=a[i];
cout<<t1<<" "<<t2<<endl;
cout<<dem1<<" "<<dem2<<endl;
cout<<t3<<endl;
cout<<t4<<endl;
for (i=1; i<=n; i++)
if (a[i]%3==0) cout<<a[i]<<" ";
return 0;
}
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 a[1000],i,n,t,dem;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
t=0;
dem=0;
for (i=1; i<=n; i++)
if ((a[i]>0) and (i%2==1))
{
t+=a[i];
dem++;
}
cout<<fixed<<setprecision(2)<<(t*1.0)/(dem*1.0);
return 0;
}
uses crt;
var a:array[1..300]of integer;
i,n,t,tb:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
t:=0;
for i:=1 to n do
if i mod 2=1 then t:=t+a[i];
tb:=0;
for i:=1 to n do
tb:=tb+a[i];
writeln('Tong cac phan tu cua day o vi tri le la: ',t);
writeln('Trung binh cong cua day la: ',tb/n:4:2);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Day A=');
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('Tong cac so chan la: ',t);
readln;
end.
uses crt;
var a:array[1..250]of integer;
i,n,dem,t,t1,t2,t3,t4:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until (0<n) and (n<=250);
for i:=1 to n do
begin
repeat
write('A[',i,']='); readln(a[i]);
until (0<a[i]) and (a[i]<=500);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2=1 then inc(dem);
writeln('So phan tu co gia tri le la: ',dem);
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+a[i];
writeln('Tong cac phan tu co chi so chan la: ',t);
t1:=0;
for i:=1 to n do
if i mod 2=1 then t1:=t1+a[i];
writeln('Tong cac phan tu co chi so le la: ',t1);
t2:=0;
for i:=1 to n do
if (i mod 2=0) and (a[i] mod 2=0) then t2:=t2+a[i];
writeln('Tong cac phan tu chan co chi so chan la: ',t2);
t3:=0;
for i:=1 to n do
if (i mod 2=1) and (a[i] mod 2=1) then t3:=t3+a[i];
writeln('Tong cac phan tu co chi so le la: ',t3);
t4:=0;
for i:=1 to n do
t4:=t4+a[i];
writeln('Trung binh cong cac so trong day la: ',t4/n:4:2);
readln;
end.