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.
Bài 1:
uses crt;
var a,b:array[1..100]of integer;
i,n,dem,t,dem1,max,tam,j,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
for i:=1 to n do
if a[i] mod 2<>0 then inc(dem);
writeln('So luong so le la: ',dem);
t:=0;
for i:=1 to n do
if a[i] mod 5=0 then t:=t+a[i];
writeln('Tong cac phan tu chia het cho 5 la: ',t);
dem1:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
inc(dem1);
b[dem1]:=a[i];
end;
max:=b[1];
for i:=1 to dem1 do
if max<b[i] then max:=b[i];
writeln('Phan tu chan lon nhat la: ',max);
writeln('Vi tri cua no trong mang la: ');
for i:=1 to n do
if max=a[i] then write(i:4);
writeln;
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
writeln('Mang duoc sap xep tang dan la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
writeln('Cac so nguyen to trong day la: ');
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then write(a[i]:4);
end;
readln;
end.
uses crt;
const fi='dayso.txt';
fa='tong.txt';
fb='kq.txt';
var f1,f2,f3:text;
a:array[1..100]of integer;
n,i,t,kt,j:integer;
begin
clrscr;
assign(f1,fi); reset(f1);
assign(f2,fa); rewrite(f2);
assign(f3,fb); rewrite(f3);
n:=0;
while not eof(f1) do
begin
n:=n+1;
readln(f1,a[n]);
end;
{--------------------------cau-a--------------------------}
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(f2,'tong cua day so la: ',t);
{--------------------------cau-b--------------------------}
writeln(f3,'cac so chan trong day la: ');
for i:=1 to n do
if a[i] mod 2=0 then write(f3,a[i]:4);
writeln(f3);
writeln(f3,'cac so le trong day la: ');
for i:=1 to n do
if a[i] mod 2<>0 then write(f3,a[i]:4);
{--------------------------cau-c--------------------------}
writeln('cac so nguyen to trong day la: ');
for i:=1 to n do
if a[i]>1 then
begin
kt:=0;
for j:=2 to a[i]-1 do
if a[i] mod j=0 then kt:=1;
if kt=0 then write(a[i]:4);
end;
close(f1);
close(f2);
close(f3);
readln;
end.
#include <bits/stdc++.h>
using namespace std;
long long a[150],i,s,n,nn;
int main()
{
cin>>n;
for (i=1; i<=n; i++) cin>>a[i];
s=1;
for (i=1; i<=n; i++)
if (a[i] %2!=0 && a[i]%3==0) s=s*a[i];
cout<<s<<endl;
nn=a[1];
for (i=1; i<=n; i++) nn=min(nn,a[i]);
for (i=n; i>=1; i--)
if (nn==a[i])
{
cout<<i<<endl;
break;
}
sort(a+1,a+n+1);
for (i=1; i<=n; i++) cout<<a[i]<<" ";
return 0;
}
Đề bài 1:
uses crt;
var a,b,c:array[1..100]of integer;
k,i,n,max,min,dem,dem1,tam,j,dem2,t:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
write('nhap k='); readln(k);
{-------------------------------cau-a--------------------------}
max:=a[1];
for i:=1 to n do
if max<a[i] then max:=a[i];
writeln('gia tri lon nhat cua mang la: ',max);
dem:=0;
for i:=1 to n do
if max=a[i] then
begin
inc(dem);
b[dem]:=i;
end;
writeln('vi tri cua no lan luot la:');
for i:=1 to dem do
write(b[i]:4);
{-----------------------------cau-b--------------------------}
writeln;
min:=a[1];
for i:=1 to n do
if min>a[i] then min:=a[i];
writeln('gia tri nho nhat cua mang la: ',min);
dem1:=0;
for i:=1 to n do
if min=a[i] then
begin
inc(dem1);
c[dem1]:=i;
end;
writeln('vi tri cua no lan luot la:');
for i:=1 to dem1 do
write(c[i]:4);
{--------------------------cau-c------------------------}
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 phan tu o vi tri chan la: ',t);
{------------------------cau-d-------------------------------}
writeln('mang duoc sap xep tang dan la: ');
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
tam:=a[i];
a[i]:=a[j];
a[j]:=tam;
end;
for i:=1 to n do
write(a[i]:4);
{------------------------cau-e-----------------------}
writeln;
dem2:=0;
for i:=1 to n do
if a[i]=k then inc(dem2);
writeln('so gia tri bang ',k,' trong day la: ',dem2);
readln;
end.
Đề bài 2:
uses crt;
var a:array[1..100]of integer;
n,i,dem,dem1,t,t1,t2:integer;
begin
clrscr;
write('n='); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{-------------------------------cau-a--------------------------}
dem:=0;
for i:=1 to n do
if a[i] mod 2=0 then inc(dem);
writeln('so luong so chan co trong mang la: ',dem);
{-------------------------------cau-b---------------------------}
dem1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then inc(dem1);
writeln('so luong so le co trong mang la: ',dem1);
{-----------------------------cau-c--------------------------}
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then t:=t+a[i];
writeln('tong cac so chan co trong mang la: ',t);
{------------------------------cau-d--------------------------}
t1:=0;
for i:=1 to n do
if a[i] mod 2<>0 then t1:=t1+a[i];
writeln('tong cac so le co trong mang la: ',t1);
{------------------------------cau-e-------------------------}
t2:=0;
for i:=1 to n do
t2:=t2+a[i];
writeln('gia tri trung binh cua mang la: ',t2/n:4:2);
readln;
end.
Câu 2:
Program HOC24;
var i,n,m: integer;
tb,tb1: longint;
a,b: array[1..32000] of integer;
begin
write('Nhap so N : '); readln(n);
tb:=0;
for i:=1 to n do
begin
write('Nhap so thu ',i,' : '); readln(a[i]);
tb:=tb+a[i];
end;
write('Nhap so M : '); readln(n);
tb1:=0;
for i:=1 to m do
begin
write('Nhap so thu ',i,' : '); readln(b[i]);
tb1:=tb1+b[i];
end;
if (tb/n)>(tb1/m) then write('Trung binh cong cua N so lon hon M so')
else write('Trung binh cong cua M so lon hon N so')
else (tb/n)=(tb1/m) then write('Trung binh cong cua M so bang hon N so');
readln
end.
Câu 1:
Program HOC24;
var s,st: string;
n,i,j: integer;
a: array[1..32000] of string;
function chuyen(x: string): string;
begin
x[1]:=upcase(x[1]);
chuyen:=x;
end;
begin
write('Nhap xau : '); readln(s);
while s[1]=#32 do delete(s,1,1);
while s[length(s)]=#32 do delete(s,length(s),1);
while pos(#32#32,s)<>0 do delete(s,pos(#32#32,s),1);
writeln('Xau sau khi xoa dau cach : ',s);
st:=s;
s:=s+' ';
while length(s)<>0 do
begin
st:=copy(s,1,pos(' ',s)-1);
n:=n+1;
a[n]:=st;
delete(s,1,pos(' ',s));
end;
write('Cac ki tu in hoa dau tien cua moi tu : ');
for i:=1 to n do write(chuyen(a[i]),' ');
writeln;
writeln('Vi tri cuoi cung cua ki tu cuoi cung so : ',length(st));
write('Sau khi xoa tu cuoi cung : ');
for i:=1 to n-1 do write(chuyen(a[i]),' ');
readln
end.
uses crt;
var a,b,c,d:array[1..100]of integer;
n,i,dem,t,max,min,j,dem1,kt,dem2,dem3,kt1:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Phan tu dau tien la: ',a[1]);
writeln('Phan tu cuoi cung la: ',a[n]);
dem:=0;
for i:=1 to n do
if a[i] mod 4=0 then inc(dem);
writeln('So luong phan tu chia het cho 4 la: ',dem);
t:=0;
for i:=1 to n do
if (a[i] mod 2=0) and (a[i]>10) then t:=t+a[i];
writeln('Tong cac so chan va lon hon 10 la: ',t);
dem1:=0;
for i:=1 to n do
if sqrt(a[i])=trunc(sqrt(a[i])) then
begin
inc(dem1);
b[dem1]:=a[i];
end;
writeln;
writeln('So luong so chinh phuong trong mang la: ',dem1);
if dem1>0 then
begin
writeln('Cac so chinh phuong co trong mang la: ');
for i:=1 to dem1 do
write(b[dem1]:4);
end;
writeln;
kt:=0;
for i:=1 to n do
if a[i] mod 2<>0 then kt:=1;
if kt=0 then writeln('Day la mang chan')
else writeln('Day khong la mang chan');
readln;
end.
Program hotrotinhoc;
var i,n,x,d: integer;
t,t1: longint;
a: array[1..500] of integer;
begin
write('N='); readln(n);
write('X='); readln(x);
t:=0; t1:=0; d:=0;
for i:=1 to n do
begin
write('a[',i,']=');
readln(a[i]);
if a[i]>0 then t:=t+a[i];
if (a[i]>0) and (a[i] mod 5=0) then t1:=t1+a[i];
if a[i]=x then inc(d);
end;
writeln('Tong cac so duong trong day A la :',t);
writeln('Tong cac so duong va chia het cho 5 trong day A la :',t1);
write('So lan xuat hien so nguyen X trong day A la :',d);
readln
end.