Bài toán. Viết chương trình xét xem một số n có phải là số nguyên tố không?
– Nếu n không chia hết mọi số i có giá trị từ 2 đến n – 1 thì n là số nguyên tố.
– Sử dụng biến ok có kiểu boolean và có giá trị ban đầu là true.
– Cho biến i chạy từ 2 đến n – 1. Xét n mod i. Nếu bằng 0 thì gán ok = false. Ngược lại vẫn để nguyên ok.
code tham khảo:
Program soNguyenTo;
uses crt;
var n, i: integer;
ok: boolean;
begin
ok:=true;
write('Nhap n: ');readln(n);
for i:= 2 to n - 1 do if n mod i = 0 then
ok :=false;
if ok then write(n,' la so nguyen to')
else write(n, ' khong la so nguyen to');
readln
end.
hello there and thank you for your information – I’ve certainly
picked up anything new from right here. I did however
expertise some technical issues using this website, as I experienced to reload the site lots of times previous
to I could get it to load properly. I had been wondering if your web host is
OK? Not that I’m complaining, but slow loading instances times will often affect your placement
in google and can damage your quality score if ads and marketing
with Adwords. Anyway I’m adding this RSS to my e-mail
and can look out for a lot more of your respective fascinating content.
Make sure you update this again soon.. Escape room lista
I was studying some of your posts on this internet site and I conceive this site is really informative!
Keep on posting.!