viết chương trình in ra tất cả số nguyên tố lớn hơn m nhỏ hơn n(m,n nhập từ bàn phím)
MIK CẦN GẤP
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 n,i,o,d:integer;
function ktnt(n:integer): integer;
var i,d:integer;
begin
d:=0;
for i:=1 to sqrt(n) do
if (n mod i=0) then d:=d+1;
if d=2 then ktnt=0
else ktnt=1;
end;
begin
readln(n);
writeln(' so nguyen to be hon hoac bang n la'); {a}
for i:=1 to n do
if ktnt(i)=0 then writeln(i);
writeln('so nguyen to nho nhat khong be hon n');
o:=n;
while o>0 do
begin
if ktnt(o)=0 then
begin
write(o);
break;
end;
o:=o+1;
end;
writeln('cặp số nguyên tố là hai số nguyên lẻ liên tiếp nhỏ hơn hoặc bằng n');
o:=0;
o:=1;
d:=0;
for i:=o+2 to n do
begin
if ktnt(i)=0 then
begin
d:=d+1;
write(i,' ');
if d<2 then continue;
end;
d:=0;
writeln;
end;
readln;
end.
Bài 3:
uses crt;
var i:integer;
{------------------chuong-trinh-con-kiem-tra-so-nguyen-to----------------------}
function ktnt(x:integer):boolean;
var kt:boolean;
i:integer;
begin
kt:=true;
for i:=2 to x-1 do
if x mod i=0 then kt:=false;
if kt=true then ktnt:=true
else ktnt:=false;
end;
{-------------------------chuong-trinh-chinh----------------------------}
begin
clrscr;
for i:=2 to 9999 do
if (ktnt(i)=true) and (ktnt(i+2)=true) then
begin
writeln(i,',',i+2);
delay(500);
end;
readln;
end.
Bài 4:
uses crt;
var a,b,c,kt:integer;
begin
clrscr;
write('Nhap ngay:'); readln(a);
write('Nhap thang:'); readln(b);
write('Nhap nam:'); readln(c);
kt:=0;
if (b=1) and (0<a) and (a<=31) then kt:=1;
if (b=2) and (0<a) and (a<=28) then kt:=1;
if (b=2) and (0<a) and (a<=29) and (c mod 4=0) then kt:=1;
if (b=3) and (0<a) and (a<=31) then kt:=1;
if (b=4) and (0<a) and (a<=30) then kt:=1;
if (b=5) and (0<a) and (a<=31) then kt:=1;
if (b=6) and (0<a) and (a<=30) then kt:=1;
if (b=7) and (0<a) and (a<=31) then kt:=1;
if (b=8) and (0<a) and (a<=31) then kt:=1;
if (b=9) and (0<a) and (a<=30) then kt:=1;
if (b=10) and (0<a) and (a<=31) then kt:=1;
if (b=11) and (0<a) and (a<=30) then kt:=1;
if (b=12) and (0<a) and (a<=31) then kt:=1;
if kt=0 then writeln('Khong hop le')
else writeln('Hop le');
readln;
end.
Program HOC24;
var a: array[1..32000] of integer;
i,max,min,n: integer;
begin
write('Nhap so phan tu N: '); readln(N);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
max:=a[1]; min:=a[1];
for i:=1 to n do
begin
if a[i]>max then max:=a[i];
if a[i]<min then min:=a[i];
end;
writeln('So nho nhat la :',max);
write('So lon nhat la: ',min);
readln
end.
uses crt;
var a:array[1..100]of integer;
i,n,max,min:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
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 la: ',max);
writeln('So nho nhat la: ',min);
readln;
end.
program Le_Nho_Hon_Hoac_Bang_n;
uses crt;
var
n, i: integer;
begin
clrscr;
write('Nhap vao mot so nguyen duong n: ');
readln(n);
while n <= 0 do
begin
writeln('So ban nhap khong hop le. Xin vui long nhap lai: ');
readln(n);
end;
clrscr;
writeln('Cac so le nho hon hoac bang ', n, ' la:');
i := 1;
while i <= n do
begin
if i mod 2 <> 0 then
writeln(i);
i := i + 1;
end;
readln;
end.
Uses crt;
var i,n: integer;
begin clrscr;
readln(n);
for i:=1 to n do if(i mod 2<>0) then writeln(i);
readln;
end.
var a:array[1..1000] of integer;
i,n,min:integer;
s:longint;
begin
write('n = ');readln(n);
for i:=1 to n do
begin
write('Nhap so thu ',i,' = ');readln(a[i]);
s:=s+a[i];
end;
writeln('Tong la ',s);
min:=a[1];
for i:=2 to n do
if a[i] < min then min:=a[i];
write('Cac so chan la ');
for i:=1 to n do
if a[i] mod 2 = 0 then write(a[i]:8);
writeln;
write('so nho nhat la ',min);
readln
end.
Câu 4:
uses crt;
var a:array[1..100]of integer;
i,n,dem,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to n do
if (10<a[i]) and (a[i]<20) then
begin
inc(dem);
t:=t+a[i];
end;
writeln('So phan tu lon hon 10 va nho hon 20 la: ',dem);
writeln('Tong cac phan tu lon hon 10 va nho hon 20 la: ',t);
readln;
end.
Câu 5:
uses crt;
var a:array[1..100]of integer;
i,n,dem,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
begin
write('A[',i,']='); readln(a[i]);
end;
dem:=0;
t:=0;
for i:=1 to n do
if a[i] mod 2=0 then
begin
inc(dem);
t:=t+a[i];
end;
writeln('So so chan la: ',dem);
writeln('Tong cac so chan la: ',t);
readln;
end.
Program vct;
uses crt;
var
m,n,i:integer;
begin
writeln('moi nhap so n '); readln(n);
writeln('moi nhap so m '); readln(m);
for i:=m to n do write(i);
readln;
end.
program bai1;
var m,n,s:longint;
begin
write('M= ');readln(m);
write('N= ');readln(n);
for k:=(m+1) to (n-1) do
begin
s:=0;
for i:=1 to n do
if (k mod i=0) then s:=s+1;
if s=2 then write(k,' ');
end;
readln
end.