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.
program timtich;
uses crt;
var i,n:integer;
tich:longint;
a:array[1..100]of integer;
begin
clrscr;
write('nhap so n:');readln(n);
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
for i:=1 to n do
write(a[i]:4);
tich:=1;
writeln;
for i:=1 to n do
if a[i] mod 2=0 then tich:=tich*a[i];
writeln('tich ca phan tu chan cua mang la:',tich);
readln;
end.
program timtong;
uses crt;
var i,n:integer;
tong:longint;
a:array[1..100]of integer;
begin
clrscr;
write('nhap so n:');readln(n);
for i:=1 to n do
begin
write('nhap phan tu a[',i,']:');readln(a[i]);
end;
for i:=1 to n do
write(a[i]:4);
tong:=0;
writeln;
for i:=1 to n do
if a[i] mod 2=0 then tong:=tong+a[i];
writeln('tong cac phan tu chan cua mang la:',tong);
tong:=0;
writeln;
for i:=1 to n do
if a[i] mod 2=1 then tong:=tong+a[i];
writeln('tong cac phan tu le cua mang la:',tong);
readln;
end.
Bài 1:
uses crt;
var a:array[1..100]of integer;
i,n,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
s:=1;
for i:=1 to n do
if a[i] mod 2=0 then s:=s*a[i];
writeln(s);
readln;
end.
Bài 1
Var s,i:integer;
tb:real;
Begin
Write('Nhap n = ');readln(n);
i:=1;
s:=0;
While i<=n do
Begin
s:=s+i;
i:=i+1;
End;
tb:=s/n;
Writeln('Tong la ',s);
Write('Trung binh la ',tb:10:2);
Readln;
End.
Bài 2
Var i,n,souoc:integer;
Begin
Write('Nhap n = ');readln(n);
i:=1;
While i <= n do
Begin
i:=i + 1;
If n mod i = 0 then souoc:=souoc + 1;
End;
If souoc = 1 then write(n,' la so nguyen to')
Else write(n,' khong la so nguyen to');
Readln;
End.
uses crt;
var a:array[1..100]of integer;
i,n,t,t1,t2,t3,min,max:integer;
kt:boolean;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Day so ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
t:=t+a[i];
kt:=true;
for i:=2 to trunc(sqrt(t)) do
if t mod i=0 then
begin
kt:=false;
break;
end;
writeln('Tong cua day so la: ',t);
if (kt=true) and (t>1) then writeln(t,' la so nguyen to')
else writeln(t,' khong la so nguyen to');
writeln('Cac so o vi tri le cua day so la: ');
t1:=0;
for i:=1 to n do
if i mod 2=1 then
begin
write(a[i]:4);
t1:=t1+a[i];
end;
writeln;
writeln('Tong cac so o vi tri le cua day so la: ',t1);
if trunc(sqrt(t1))=sqrt(t1) then writeln(t1,' la so chinh phuong')
else writeln(t1,' khong la so chinh phuong');
writeln('Cac so o vi tri chan cua day so la: ');
t2:=0;
for i:=1 to n do
if i mod 2=0 then
begin
write(a[i]:4);
t2:=t2+a[i];
end;
writeln;
writeln('Tong cac so o vi tri chan cua day so la: ',t2);
t3:=0;
for i:=1 to t2 do
if t2 mod i=0 then t3:=t3+i;
if t3=t2 then writeln(t2,' la so hoan hao')
else writeln(t2,' khong la so hoan hao');
max:=a[1];
min:=a[1];
for i:=1 to n do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
writeln('So lon nhat cua day la: ',max);
writeln('So nho nhat cua day la: ',min);
writeln('Tong cua so lon nhat va so nho nhat la: ',max+min);
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
for i:=1 to n do
if a[i] mod 2=0 then write(a[i]:4);
readln;
end.
uses crt;
var a:array[1..1000000] of longint;
n,i:longint;
begin
clrscr;
write('Nhap so luong phan tu: '); readln(n);
for i:=1 to n do
begin
write('Nhap phan tu thu ',i,': '); readln(a[i]);
end;
write('Cac so chan: ');
for i:=1 to n do if a[i] mod 2=0 then write(a[i],' ');
readln;
end.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
for i:=1 to n do readln(a[i]);
for i:=1 to n do write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
if a[i]>0 then t:=t+a[i];
writeln(t);
readln;
end.
uses crt;
var a:array[1..100]of integer;
n,i,t,kt,j,t1,t2,t3,max,min:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
writeln('Day so ban vua nhap la: ');
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln('Tong cua day so vua nhap la: ',t);
kt:=0;
for i:=2 to trunc(sqrt(t)) do
if t mod i=0 then
begin
kt:=1;
break;
end;
if (kt=0) and (t>1) then writeln(t,' la so nguyen to');
else writeln(t,' khong la so nguyen to');
t1:=0;
writeln('Cac so o vi tri le cua day la: ');
for i:=1 to n do
if i mod 2=1 then
begin
write(a[i]:4);
t1:=t1+a[i];
end;
writeln;
writeln('Tong cac so o vi tri le la: ',t1);
if trunc(sqrt(t1))=sqrt(t1) then writeln(t1,' la so chinh phuong')
else writeln(t1,' khong la so chinh phuong');
t2:=0;
writeln('Cac so o vi tri chan la: ');
for i:=1 to n do
if i mod 2=0 then
begin
write(a[i]:4);
t2:=t2+a[i];
end;
writeln;
writeln('Tong cac so o vi tri chan la: ',t2);
t3:=0;
for i:=1 to t2 do
if t2 mod i=0 then t3:=t3+i;
if t3=t2 then writeln(t2,' la so hoan hao')
else writeln(t2,' khong la so hoan hao');
max:=a[1];
min:=a[1];
for i:=1 to n do
begin
if max<a[i] then max:=a[i];
if min>a[i] then min:=a[i];
end;
writeln('Gia tri lon nhat la: ',max);
writeln('Gia tri nho nhat la: ',min);
writeln('Tong cua hai so lon nhat va nho nhat la: ',max+min);
readln;
end.
BT1:
Uses crt;
var i,n: integer;
a: array[1..100] of longint;
begin clrscr;
readln(n);
for i:=1 to n do
read(a[i]); readln;
writeln(a[i]:3);
readln;
end.
BT2:
Uses crt;
var i,n,k: integer;
a: array[1..100] of longint;
begin clrscr;
readln(n);
for i:=1 to n do
read(a[i]); readln;
for i:=1 to n do begin
if(a[i] mod 2=0) then k:=k+a[i];
end;
writeln(k);
readln;
end.
Câu 1:Viết chương trình nhập vào 1 dãy N số nguyên. Đưa ra màn hình tổng các số dương chia hết cho 3
Câu 1:
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;
T:=0;
For i:=1 to n do
If (a[i]>0) and (a[i] mod 3=0) then t:=t+a[i];
Writeln(t);
Readln;
End.
uses crt;
var a:array[1..100]of integer;
i,n,t:integer;
begin
clrscr;
readln(n);
for i:=1 to n do
readln(a[i]);
for i:=1 to n do
write(a[i]:4);
writeln;
t:=0;
for i:=1 to n do
t:=t+a[i];
writeln(t);
writeln(t/n:4:2);
readln;
end.