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.
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.
program tim_uoc;
uses crt;
var i,n,tong:integer;
begin
clrscr;
write('nhap so n:');readln(n);
i:=1;tong:=0;
writeln('cac uoc cua ',n,' la:');
while i<=n do
if n mod i=0 then
begin
write(i:3);
inc(i);
end;
writeln;
i:=1;writeln('cac uoc chan:');
while i<=n do
begin
if n mod i=0 then
begin
if i mod 2=0 then write(i:3);
tong:=tong+i;
end;
end;
writeln;
write('tong cac uoc chan:',tong);
readln;
end.
uses crt;
var n,i,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
i:=1;
writeln('Cac uoc cua ',n,' la: ');
while i<=n do
begin
if n mod i=0 then write(i:4):
i:=i+1;
end;
writeln;
writeln('Cac uoc chan cua ',n,' la: ');
t:=0;
i:=1;
while i<=n do
begin
if (n mod i=0) then
begin
t:=t+i;
write(i:4);
end;
inc(i);
end;
writeln('Tong cac uoc chan cua ',n,' la: ',t);
readln;
end.
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(s);
readln;
end.
program DemSoChiaHetCho5;
var
n, i, count: integer;
begin
write('Nhap n: ');
readln(n);
i := 1;
count := 0;
while i <= n do
begin
if i mod 5 = 0 then
count := count + 1;
i := i + 1;
end;
writeln('Co ', count, ' so tu nhien chia het cho 5 trong khoang tu 1 den ', n);
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.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,t=0,i,dem=0;
cin>>n;
for (int i=1; i<=n; i++)
if (i%2==0)
{
t=t+i;
dem++;
}
cout<<fixed<<setprecision(2)<<(t*1.0)/(dem*1.0);
return 0;
}
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.
Bài 1:
*Dùng For..do
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
if n mod i=0 then write(i:4);
readln;
end.
*Dùng While..do
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
i:=1;
while i<=n do
begin
if n mod i=0 then write(i:4);
inc(i);
end;
readln;
end.
Bài 2:
*Dùng For..do
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
if (n mod i=0) and (i mod 2=0) then write(i:4);
readln;
end.
*Dùng While..do
uses crt;
var n,i:integer;
begin
clrscr;
write('Nhap n='); readln(n);
i:=1;
while i<=n do
begin
if (n mod i=0) and (i mod 2=0) then write(i:4);
inc(i);
end;
readln;
end.
Bài 3:
*Dùng For..do
uses crt;
var n,i,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t:=0;
for i:=1 to n do
if n mod i=0 then t:=t+i;
writeln('Tong cac uoc cua ',n,' la: ',t);
readln;
end.
*Dùng While..do
uses crt;
var n,i,t:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t:=0;
i:=1;
while i<=n do
begin
if n mod i=0 then t:=t+i;
inc(i);
end;
writeln('Tong cac uoc cua ',n,' la: ',t);
readln;
end.
Bài 4:
*Dùng For..do
uses crt;
var i,dem:integer;
begin
clrscr;
dem:=0;
for i:=100 to 999 do
if i mod 3=0 then inc(dem);
writeln('So cac so co 3 chu so chia het cho 3 la: ',dem);
readln;
end.
*Dùng While..do
uses crt;
var i,dem:integer;
begin
clrscr;
dem:=0;
i:=100;
while i<=999 do
begin
if i mod 3=0 then inc(dem);
inc(i);
end;
writeln('So cac so co 3 chu so chia het cho 3 la: ',dem);
readln;
end.
Bài 5:
*Dùng For..do
uses crt;
var i,t,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t:=0;
for i:=1 to n do
if i mod 2=0 then t:=t+i;
writeln('Tong cac so chan tu 1 toi ',n,' la: ',t);
readln;
end.
*Dùng While..do
uses crt;
var i,t,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t:=0;
i:=1;
while i<=n do
begin
if i mod 2=0 then t:=t+i;
inc(i);
end;
writeln('Tong cac so chan tu 1 toi ',n,' la: ',t);
readln;
end.
Bài 6:
*Dùng For..do
uses crt;
var i,t,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t:=0;
for i:=1 to n do
if i mod 2=1 then t:=t+i;
writeln('Tong cac so le tu 1 toi ',n,' la: ',t);
readln;
end.
*Dùng While..do
uses crt;
var i,t,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
t:=0;
i:=1;
while i<=n do
begin
if i mod 2=1 then t:=t+i;
inc(i);
end;
writeln('Tong cac so le tu 1 toi ',n,' la: ',t);
readln;
end.
Bài 7:
*Dùng For..do
uses crt;
var i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
for i:=1 to n do
if i mod 5=0 then write(i:4);
readln;
end.
*Dùng While..do
uses crt;
var i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
i:=1;
while i<=n do
begin
if i mod 5=0 then write(i:4);
inc(i);
end;
readln;
end.
Bài 8:
*Dùng For..do
uses crt;
var i,n,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
dem:=0;
for i:=1 to n do
if (n mod i=0) and (i mod 2=1) then inc(dem);
writeln('So uoc le cua ',n,' la: ',dem);
readln;
end.
*Dùng While..do
uses crt;
var i,n,dem:integer;
begin
clrscr;
write('Nhap n='); readln(n);
dem:=0;
i:=1;
while i<=n do
begin
if (n mod i=0) and (i mod 2=1) then inc(dem);
i:=i+1;
end;
writeln('So uoc le cua ',n,' la: ',dem);
readln;
end.
Bài 9:
*Dùng For..do
uses crt;
var i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
writeln('Bang cuu chuong ',n,' la: ');
for i:=1 to 10 do
writeln(n*i);
readln;
end.
*Dùng While..do
uses crt;
var i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
writeln('Bang cuu chuong ',n,' la: ');
i:=1;
while i<=10 do
begin
writeln(n*i);
inc(i);
end;
readln;
end.
Bài 10:
*Dùng For..do
uses crt;
var i,n,kt:integer;
begin
clrscr;
write('Nhap n='); readln(n);
kt:=0;
for i:=2 to n-1 do
if n mod i=0 then kt:=1;
if kt=0 then write(n,' la so nguyen to')
else write(n,' la hop so');
readln;
end.
*Dùng While..do
uses crt;
var i,n:integer;
begin
clrscr;
write('Nhap n='); readln(n);
i:=2;
while (n mod i<>0) and (i<=n) do
begin
inc(i);
end;
if i=n then writeln(n,' la so nguyen to')
else writeln(n,' la hop so');
readln;
end.