For-Do
1.program bai1;
uses crt;
var i:integer;
clrscr;
for i:=0 to 50 do
if (i mod 2 =0) then
writeln('Can bac 2 cua ',i,' la ',sqrt(i):3:5);
readln;
end.
2.program bai2;
uses crt;
var thuong,du,a:integer;
clrscr;
write('nhap a: ');
readln(a);
thuong:=a div 5;
du:= a mod 5;
writeln('Thuong nguyen cua a chia cho 5 la: ',thuong);
writeln('Du cua a chia cho 5 la: ',du);
readln;
end.
3.program bai3;
uses crt;
var x:integer;
clrscr;
writeln('voi y=x^2+2x+1 va x nguyen thuoc (-2,5)');
for x:=-2 to 5 do
writeln('voi x = ',x,' thi y = ',x*x+2*x+1);
writeln('');
writeln('voi y= can bac 2 cua x va x nguyen thuoc (1,5)');
for x:=1 to 5 do
writeln('voi x = ',x,' thi y = ',sqrt(x):3:5);
readln;
end.
4.program bai4;
uses crt;
var x,y:integer;
clrscr;
writeln('Tim cac nguyem nguyen duong cua phuong trinh 2x+4y=100');
for y:=1 to 50 do
writeln('nghiem thu ',y,' cua phuong trinh la: x= ',100-2*y,' y=',y);
readln;
end.
5.program bai5;
uses crt;
var i,a1,a2,a3,j:integer;
clrscr;
writeln('Cac so co 3 chu so chia cho 6 du 2 va tong cac chu so = 20 la: ');
for i:=100 to 999 do
a1:=i div 100;
a2:=(i - a1*100) div 10;
a3:=(i - a1*100 -a2*10);
if(i mod 6 =2 ) and (a1+a2+a3=20) then
writeln('so thu ',j,' la: ',i);
j:=j+1;
end;
end;
readln;
end.
6.program bai6;
uses crt;
var a1,a2,a3,a4,a,i:integer;
clrscr;
i:=1;
writeln('Cac so co 4 chu so co hang tram+ hang nghin = hang chuc + hang don vi');
for a:=1000 to 9999 do
a1:=a div 1000;
a2:=(a - a1*1000) div 100;
a3:=(a - a1*1000 - a2*100) div 10;
a4:=(a - a1*1000 - a2*100 - a3*10);
if(a1+a2=a3+a4) then
writeln('So thu ',i,' la: ',a);
i:=i+1;
end;
end;
readln;
end.
7.program bai7;
uses crt;
var x,y:integer;
clrscr;
writeln('Vua ga vua cho bo lai cho tron 36 con 100 chan chan~');
for x:=1 to 36 do
for y:=1 to 25 do
if (x+y=36) and (2*x+4*y=100) then
writeln('So ga la: ',x,' So cho la: ',y);
readln;
end.
8.program bai8;
uses crt;
var i,j:integer;
clrscr;
for i:=1 to 9 do
for j:=1 to 9 do
writeln(i,' x ',j,' = ',i*j);
readln;
end.
9.program bai9;
uses crt;
var s,a,b,i:integer;
clrscr;
i:=1;
writeln('Cac so tu nhien <=1000 ma no bang tong uoc cua chinh no la: ');
for a:=1 to 1000 do
s:=0;
for b:=1 to a-1 do
if(a mod b =0) then
s:=s+b;
end;
if(s=a) then
writeln('So thu ',i,' la:',a);
i:=i+1;
end;
end;
readln;
end.
10.program bai10;
uses crt;
var tg,td,tn:integer;
clrscr;
writeln('100 trau 100 bo co.. trau dung an 5 trau .. trau nam an 3 ..trau gia 3 con 1 bo');
for td:=0 to 20 do
for tn:=0 to 34 do
tg:=100-(td+tn);
if (5*td+3*tn+tg/3=100) then
writeln('So trau dung la: ',td,' So trau nam la: ',tn,' So trau gia la: ',tg);
end;
readln;
end.
If then
1.program bai1;
uses crt;
var dtb:real;
clrscr;
write('Moi nhap vao diem trung binh: ');
readln(dtb);
if (dtb>10) and (dtb<0) then
writeln('diem trung binh khong hop le')
else
if(dtb<=10) and (dtb>=9)then
writeln('hoc sinh gioi')
else
if(dtb<9) and (dtb>=7)then
writeln('hoc sinh kha')
else
if(dtb<7) and (dtb>=5) then
writeln('hoc sinh trung binh')
else
writeln('hoc sinh yeu');
readln;
end.
2.program bai2;
uses crt;
var a,can:real;
clrscr;
write('nhap a');
readln(a);
if(a<0) then
writeln('a khong ton tai can bac 2')
else
can:=sqrt(a);
writeln('can cua a la : ',can);
end;
readln;
end.
3.program bai3;
uses crt;
var a:integer;
clrscr;
write('nhap a: ');
readln(a);
if(a=0)then
writeln('a la so khong')
else
if(a<0)then
writeln(a,' la so nguyen am')
else
writeln(a,' la so nguyen duong');
readln;
end.
4.program bai4;
uses crt;
var a,b,c,d,i:integer;
clrscr;
write('nhap a: ');
readln(a);
i:=0;b:=0;c:=0;d:=0;
if (a mod 2=0) then b:=1;
if (a mod 3=0) then c:=1;
if (a mod 5=0) then d:=1;
if(b=1)and(c=1)and(d=1)then writeln(a,'chia het cho 2,3,5');
if(b=1)and(c=1)and(d=0)then writeln(a,'chia het cho 2,3 va khong chie het cho 5');
if(b=1)and(c=0)and(d=1)then writeln(a,' chia het cho 2,5 va khong chia het cho 3');
if(b=1)and(c=0)and(d=0)then writeln(a,'chia het cho 2 va khong chia het cho 3,5');
if(b=0)and(c=1)and(d=1)then writeln(a,'chia het cho 3,5 va khong chia het cho 2');
if(b=0)and(c=1)and(d=0)then writeln(a,'chia het cho 3 va khong chia het cho 2,5');
if(b=0)and(c=0)and(d=1)then writeln(a,'chia het cho 5 va khong chia het cho 2,3');
if(b=0)and(c=0)and(d=0)then writeln(a,'khong chia het cho 2,3,5');
readln;
end.
In Đam
8.program bai8;
uses crt;
var i,j,n:integer;
clrscr;
write('nhap n: ');
readln(n);
for i:=1 to n do
for j:=1 to i do
write('*');
writeln(' ');
end;
readln;
end.
9.program bai9;
uses crt;
var i,j,n:integer;
clrscr;
write('nhap n: ');
readln(n);
for i:=n downto 1 do
for j:=1 to i do
write('*');
writeln(' ');
end;
readln;
end.
13.program bai13;
uses crt;
var i,s,n:integer;
clrscr;
write('nhap n: ');
readln(n);
s:=0;
for i:=1 to n do
if(i mod 2=0) then s:=s+i;
writeln('Tong cac so chan tu 1 den ',n,' la: ',s);
readln;
end.
14.program bai14;
uses crt;
var i,n:integer;
clrscr;
repeat
write('nhap n: ');
readln(n);
until (n>0);
for i:=1 to 9 do
writeln(n,' x ',i,' = ',n*i);
readln;
end.
15.program bai15;
uses crt;
var i,n:integer;
s,x:real;
clrscr;
repeat
write('nhap so tien gui: ');
read(x);
write('nhap so nam: ');
readln(n);
until (x>0) and (n>0);
s:=x;
for i:=1 to n*12 do
s:=s+s*0.0015;
writeln('So tien nguoi do co sau ',n,' nam la: ',s:10:6,'trieu dong');
readln;
end.
16.program bai16;
uses crt;
var s,n,i:integer;
clrscr;
write('nhap n: ');
readln(n);
s:=1;
for i:=1 to n do
s:=s*i;
writeln(n,'! = ',s);
readln;
end.
17.program bai17;
uses crt;
var s,i,n:integer;
clrscr;
repeat
write('nhap n: ');
readln(n);
until n>=0;
s:=1;
for i:=1 to n do
s:=s*2;
writeln('2 ^ ',n,' = ',s);
readln;
end.
18.program bai18;
uses crt;
var s,x:real;
i,n:integer;
clrscr;
repeat
write('nhap x: ');
readln(x);
write('nhap n: ');
readln(n);
until n>=0;
s:=1;
for i:=1 to n do
s:=s*x;
writeln(x:5:5,' ^ ',n,' = ',s:5:5);
readln;
end.
19.program bai19;
uses crt;
var n:integer;
y:real;
clrscr;
y:=0;
for n:=1 to 50 do
y:=y+(n/(n+1));
writeln('Tong xich ma cua n/(n+1) voi n chay tu 1 den 50 la: ',y:3:5);
readln;
end.
20.program bai20;
uses crt;
var n,i,s:integer;
clrscr;
repeat
write('nhap n: ');
readln(n);
until n>0;
s:=0;
for i:=1 to n do
s:=s+sqr(i);
writeln('Tong xich ma cua n^2 voi n chay tu 1 den ',n,' la: ',s);
readln;
end.
21. program bai21;
uses crt;
var n,i:integer;
s:real;
clrscr;
repeat
write('nhap n: ');
readln(n);
until n>0;
s:=0;
for i:=1 to n do
s:=s+(1/i);
writeln('Tong xich ma cua 1/n voi n chay tu 1 den ',n,' la: ',s:5:5);
readln;
end.
22.program bai22;
uses crt;
var j,n,i:integer;
clrscr;
repeat
write('nhap n: ');
readln(n);
until n>=0;
j:=0;
if(n=0) or (n=1) then writeln(n,' ko la so nguyen to') else
for i:=2 to n div 2 do
if(n mod i =0 ) then j:=j+1;
if(j=0) then
writeln(n,' la so nguyen to')
else
writeln(n,' ko la so nguyen to');
end;
readln;
end.
23.program bai23;
uses crt;
var n,a,b,c,d,e,i:integer;
clrscr;
repeat
write('nhap so tien: ');
readln(n);
until n>0;
i:=1;
for a:=0 to n div 50 do
for b:=0 to n div 10 do
for c:=0 to n div 5 do
for d:=0 to n div 2 do
for e:=0 to n div 1 do
if(a*50+b*10+c*5+d*2+e*1=n) then
writeln('Cach doi thu ',i,' la: ',a,' :50$ ',b,' :10$ ',c,' :5$ ',d,' :2$ ',e,' :1$');
i:=i+1;
end;
readln;
end.
24.program bai24;
uses crt;
var i:integer;
a:char;
clrscr;
for i:=65 to 90 do
writeln(chr(i),' : ',i);
for i:=97 to 122 do
writeln(chr(i),' : ',i);
readln;
end.
While Do
3.program bai3;
uses crt;
var n,gt,j:integer;
e:real;
clrscr;
gt:=1;
e:=1;
n:=1;
while((1/gt) > 0.000002) do
gt:=1;
for j:=1 to n do
gt:=gt*j;
e:=e+(1/gt);
n:=n+1;
end;
writeln('e(n)=1+1/1!+1/2!+...+1/n! = ',e:5:5,' voi 1/n! < 2x10^-6');
readln;
end.
4.program bai4;
uses crt;
var n:integer;
a,s:real;
clrscr;
write('nhap a: ');
readln(a);
s:=0;
n:=1;
while (s<a) do
s:=s+1/n;
n:=n+1;
end;
writeln('e(n)=1+1/2+1/3+...+1/n > ',a:5:5,' voi n >= ',n-1);
readln;
end.
5.program bai5;
uses crt;
var n,i,ulln:integer;
clrscr;
write('nhap n: ');
readln(n);
if(n mod 2<>0) then
writeln('uoc so le luon nhat cua ',n,' la: ',n)
else
i:=n-1;
while((n mod i <> 0) ) do
i:=i-2;
writeln('',i);
end;
readln;
end.
6.program bai6;
uses crt;
var n,uoc:integer;
clrscr;
repeat
write('nhap n: ');
readln(n);
until n>0;
uoc:=n;
while (uoc >0) do
if(( n mod uoc = 0) and ( ln(uoc) / ln(2) - trunc( ln(uoc) / ln(2))=0)) then
writeln('uoc lon nhat cua ',n,' va la luy thua cua 2 la: ',uoc );
break;
end;
uoc:=uoc-1;
end;
readln;
end.
7.program bai7;
uses crt;
var n,i,j,a,nt,kt:integer;
clrscr;
write('nhap n: ');
readln(n);
nt:=2;
i:=1;
kt:=0;
while(n>0)do
writeln('so nguyen to thu ',i,' la: ',nt);
i:=i+1;
while (kt=0)do
nt:=nt+1;
a:=0;
for j:=2 to nt-1 do
if(nt mod j = 0 ) then begin a:=a+1; break; end;
if (a=0) then break;
end;
n:=n-1;
end;
readln;
end.
8.program bai8;
uses crt;
var i,j,nt,n,dem:integer;
clrscr;
repeat
write('nhap n: ');
readln(n);
until n>=2;
nt:=n-1;
dem:=1;
j:=0;
while(nt>=2) do
for i:=2 to nt-1 do
if(nt mod i =0) then begin j:=j+1; break; end;
if(j=0) then
writeln('so nguyen to thu ',dem,' la: ',nt) ;
dem:=dem+1;
end;
nt:=nt-1;
j:=0;
end;
readln;
end.
9.program bai9;
uses crt;
var tcha,tcon,n:integer;
clrscr;
repeat
write('nhap tuoi cha: ');
readln(tcha);
write('nhap tuoi con: ');
readln(tcon);
until (tcha>2*tcon) and (tcha-tcon>=25);
n:=0;
while(tcha<>2*tcon) do
tcha:=tcha+1;
tcon:=tcon+1;
n:=n+1;
end;
writeln('Vay sau ',n,' nam nua tuoi cha gap 2 lan tuoi con');
readln;
end.
10.program bai10;
uses crt;
var s:real;
i,a,b:integer;
clrscr;
repeat
write('nhap a: ');
readln(a);
write('nhap b: ');
readln(b);
until b>a;
s:=0;
while (b>s) do
s:=s+a*0.003;
i:=i+1;
end;
writeln('nguoi do gui so tien ',a,' dong sau ',i,' thang thi nguoi do rut dc nhieu hon ',b,'dong');
readln;
end.
Bạn đang đọc truyện trên: Truyen2U.Pro