Bài 1: Viết chương trình Pascal nhập n (n>0). Xuất ra màn hình:
các số nguyên tố từ 2 đến n và cho biết có bao nhiêu số nguyên tố từ 2 đến n
Lưu ý : Dùng lệnh While...do hoặc Repeat....until
Viết chương trình pascal nhập n (N > 0) Xuất ra màn hình:
+ Các ước của n và cho biết có bao nhiêu ước.
+ Tổng các ước của n.
+ Xét tổng các ước của n có phải là số nguyên tố không?
Lưu ý: chỉ dùng lệnh while...do
var i,n,s,du,dem:integer;
Begin
While n<=0 do
Begin
Write('N = ');readln(n);
End;
For i:=1 to n do
If n mod i = 0 then
Begin
Write(i:7);
du:=du+1;
s:=s+i;
End;
Writeln('So uoc cua ',n,' la ',du);
Writeln('Tong cac uoc cua ',n,' la ',s);
For i:=1 to s do
If s mod i = 0 then dem:=dem+1;
If dem=2 then write(s,' la so nguyen to')
Else write(s,' khong la so nguyen to');
Readln;
End.
Bài 1: Viết chương trình pascal thực hiện các yêu cầu sau: a) Nhập từ bàn phím 1 số nguyên n b) In ra màn hình kết quả tổng các số nguyên từ 1 đến n (sử dụng câu lệnh lặp while...do) Bài 2: Viết chương trình pascal thực hiện câc yêu cầu sau: a) Nhập từ bàn phím 1 số nguyên dương n b) In ra màn hình kết quả tổng các số lẻ từ 1 đến n (sử dụng câu lệnh lặp while...do giúp mình với mình đang cần gấp rất gấp luôn
Bài 1:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
inc(i);
end;
writeln('Tong cac so trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Bài 2:
uses crt;
var n,i,s:integer;
begin
clrscr;
write('Nhap n='); readln(n);
s:=0;
i:=1;
while i<=n do
begin
s:=s+i;
i:=i+2;
end;
writeln('Tong cac so le trong khoang tu 1 den ',n,' la: ',s);
readln;
end.
Viết chương trình Pascal nhập số tự nhiên n từ bàn phím. Xuất ra màn hình:
Các số nguyên tố từ 2 đến n
pascal nha pls
Program HOC24;
var i,d,j,n integer;
begin
readln(n);
for i:=2 to n do
begin
d:=0;
for j:=1 to i do
if i mod j =0 then d=d+1;
if d=2 then write(i,' ');
end;
readln
end.
Viết chương trình pascal nhập vào số nguyên n. Xuất kết quả ra màn hình ?
a) Các số nguyên liên tiếp từ 1 đến n ea màn hình?
b) Xuất các số nguyên tố có trong đoạn từ 1 đến n ra màn hình ?
Vd:
Nhap n=6
Cac so nguyen la
6 la hop so.
Vd:
Nhap n=11
Cac uoc cua n la : 1,11
11 la so nguyen to
Giúp mình với ạ, mình đang cần gấp
uses crt;
var a:array[1..100]of integer;
i,n,dem,kt,j:integer;
begin
clrscr;
readln(n);
for i:=1 to n do write(i:4);
writeln;
for i:=2 to n do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then write(i:4);
end;
readln;
end.
viết công thức pascal nhập số n từ bàn phím, thực hiện xuất ra màn hình: +các số nguyên tố từ 2 đến n
+các số chính phương từ 0 đến n
+các số hoàn hảo từ 1 đến n
Làm giúp mình với!!!
uses crt;
var n,i,kt,j,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
writeln('Cac so nguyen to trong khoang tu 2 toi ',n,' la: ');
for i:=2 to n do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then write(i:4);
end;
writeln;
writeln('Cac so chinh phuong trong khoang tu 0 toi ',n,' la: ');
for i:=0 to n do
if trunc(sqrt(i))=sqrt(i) then write(i:4);
writeln;
writeln('Cac so hoan hao trong khoang tu 1 toi ',n,' la: ');
for i:=1 to n do
begin
t:=0;
for j:=1 to i-1 do
if i mod j=0 then t:=t+j;
if t=i then write(i:4);
end;
readln;
end.
Viết chương trình nhập vào từ bàn phím một số nguyên dương n, in ra màn hình các số lẻ nhỏ hơn hoặc bằng số nguyên dương n. Chương trình yêu cầu nhập lại nếu n <=0. (Sử dụng câu lệnh While … do)
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.
(Viết chương trình Pascal sử dụng câu lệnh while...do)
1. Viết chương trình nhập vào 1 dãy gồm n số nguyên và tính tổng, trung bình của dãy vừa nhập.
2. Viết chương trình nhập 1 số nguyên x, kiểm tra số vừa nhập có phải số nguyên tố hay không.
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.
viết chương trình nhập số nguyên n<1000 và cho biết có bao nhiêu số nguyên tố từ 1 đến n?
uses crt;
var n,i,kt,j,dem:integer;
begin
clrscr;
repeat
write('Nhap n='); readln(n);
until n<1000;
dem:=0;
for i:=2 to n do
begin
kt:=0;
for j:=2 to i-1 do
if i mod j=0 then kt:=1;
if kt=0 then inc(dem);
end;
writeln('So luong so nguyen to trong khoang tu 1 toi ',n,' la: ',dem);
readln;
end.
Viết chương trình in ra màn hình Dãy số từ 1 đến n bằng ngôn ngữ lập trình Pascal dùng lệnh lặp for..... do với n được nhập vào từ bàn phím
Var i,n:integer;
Begin
Write('n = ');readln(n);
Write('Day so tu 1 den ',n,' la ');
For i:=1 to n do write(i:8);
Readln
End.