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..200]of integer;
n,i,k,t,t1: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 2<>0 then t:=t+a[i];
t1:=0;
for i:=1 to n do
if a[i] mod k=0 then t1:=t1+a[i];
writeln('Tong cac phan tu le la: ',t);
writeln('Tong cac phan tu la boi cua ',k,' la: ',t1);
readln;
end.
uses crt;
var a:array[1..100]of integer;
n,i,k,max,min,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);
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('Gia tri lon nhat la: ',max);
writeln('Vi tri la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
writeln;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('Gia tri nho nhat la: ',min);
writeln('Vi tri la: ');
for i:=1 to n do
if min=a[i] then write(i:4);
writeln;
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+sqr(a[i]);
writeln('Tong binh phuong cac gia tri o vi tri chan la: ',t);
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
Program HOC24;
var a: array[1..250] of integer;
i,n: integer;
t: longint;
begin
write('Nhap N: '); readln(N);
t:=0;
for i:=1 to n do if i mod 2=1 then t:=t+i;
write('Tong cac phan tu o vi tri le la: ',t);
readln
end.
uses crt;
var a:array[1..250]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;
t:=0;
for i:=1 to n do
if (a[i] mod 2<>0) and (i mod 2=0) then t:=t+a[i];
writeln(t);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[10000],i,n;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
for (i=1; i<=n; i++) cout<<a[i]<<" ";
cout<<endl;
t=0;
for (i=1; i<=n; i++) if (a[i]%2==0) t+=a[i];
cout<<"Tong cac so chan la: "<<t<<endl;
sort(a+1,a+n+1);
cout<<"Day so giam dan la: ";
for (i=n; i>=1; i--) cout<<a[i]<<" ";
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;
}
bạn viết rõ ra được không ạ. mình không hiểu