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 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.
program tim_max;
uses crt;
var i,n,max:integer;
x:array[1..100]of byte;
begin
clrscr;
write('nhap so n:');readln(n);
i:=1;
while i<=n do
begin
write('x[',i,']=');readln(x[i]);
i:=i+1;
end;
max:=x[1];i:=1;
while i<=n do
begin
if max<x[i] then max:=x[i];
i:=i+1;
end;
write('so lon nhat la:',max);
readln;
end.
var i,n,s:integer;
begin
write('nhap n = ');readln(n);
i:=1;
while i<=n do
begin
s:=s+i;
i:=i+1;
end;
write('Tong la ',s);
readln;
end.
program Tim_Uoc;
uses crt;
var
n, i: integer;
begin
clrscr;
write('Nhap vao mot so nguyen duong n: ');
readln(n);
writeln('Cac uoc cua so ', n, ' la: ');
for i:=1 to n do
begin
if n mod i = 0 then
writeln(i);
end;
readln;
end.
Cách 1 dùng lệnh for do:
Uses crt;
var i,n,k: integer;
begin clrcsr;
readln(n);
for i:=1 to n do begin
if(i mod 2=0) and (i>=10) then k:=k*i;
end;
writeln(k);
readln;
end.
Cách 2 dùng lệnh while do
Uses crt;
var m,n,o: integer;
begin clrcsr;
readln(n);
o:=1;
m:=1;
while (m<n) do begin
m:=m+1;
if(m mod 2=0) and (m>=10) then o:=o*m;
end;
writeln(o);
readln;
end.
uses crt;
var i,n:integer;
s:real;
begin
clrscr;
write('Nhap n='); readln(n);
s:=1;
i:=1;
while i<=n do
begin
s:=s*i;
i:=i+1;
end;
writeln(s:0:0);
readln;
end.
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.
uses crt;
var s,p,i,n:integer;
begin
clrscr;
readln(n);
s:=0;
p:=1;
for i:=1 to n do
begin
s:=s+i;
p:=p*i;
end;
writeln(s);
writeln(p);
readln;
end.
Program HOC24;
var i,n: integer;
begin
write('n='); readln(n);
i:=1;
while i<n do
begin
if (n mod i=0) and (i<n) then write(i,' ');
i:=i+1;
end;
readln
end.