Bài 7. Câu lênh lặp

Nguyễn Huỳnh Như

Sử dụng lệnh For...do nha, mn giúp mình với!!!

undefined

KhảTâm
14 tháng 4 2021 lúc 12:21

mình ghi phần chính thôi nhé!

writeln('nhap n');readln(n);

1.For i:=1 to 9 do writeln(n,'x',i,'=',n*i);

2.for i:=1 to n do if (n mod i =0) and ( i mod 2 = 0) then writeln(i);

3.for i:=1 to n do if (n mod i =0) and ( i mod 2 = 1) then writeln(i);

4. uocchung:=1;for i:=1 to n do if n mod i = 0 then uocchung:=uocchung+i;

5. For i:=2 to n-1 do if n mod i = 0 then begin

if n = i then writeln( n,' la so nguyen to') else writeln(n, 'khong phai la so nguyen to');

 

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:47

Câu 1: 

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,'=',n*i);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:47

Câu 2: 

uses crt;

var i,n: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.

Bình luận (2)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:48

Câu 3: 

uses crt;

var i,n:integer;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do

if (n mod i=0) and (i mod 2=1) then write(i:4);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:48

Câu 4: 

uses crt;

var i,n,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(t);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:49

Câu 5: 

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

begin

kt:=1;

break;

end;

if (kt=0) and (n>1) then writeln(n,' la so nguyen to')

else writeln(n,' khong la so nguyen to');

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:52

Câu 6: 

uses crt;

var i,a,b,ucln,x,y:integer;

begin

clrscr;

write('Nhap a='); readln(a);

repeat
write('Nhap b='); readln(b);

until b<>0;

if a<b then 

begin

ucln:=1;

for i:=1 to a do

  if (a mod i=0) and (b mod i=0) then 

    begin

if ucln<i then ucln:=i;

end;

end

else begin

ucln:=1;

for i:=1 to b do 

  if (a mod i=0) and (b mod i=0) then 

begin

if ucln<i then ucln:=i;

end;

end;

x:=a div ucln;

y:=b div ucln;

writeln(a,'/',b,'=',x,'/',y);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:52

Câu 7:

uses crt;

var i,a,b,ucln:integer;

begin

clrscr;

write('Nhap a='); readln(a);

repeat
write('Nhap b='); readln(b);

until b<>0;

if a<b then 

begin

ucln:=1;

for i:=1 to a do

  if (a mod i=0) and (b mod i=0) then 

    begin

if ucln<i then ucln:=i;

end;

end

else begin

ucln:=1;

for i:=1 to b do 

  if (a mod i=0) and (b mod i=0) then 

begin

if ucln<i then ucln:=i;

end;

end;

writeln(ucln);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:54

Câu 9:

uses crt;

var t,i,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(t);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:54

Câu 11:

uses crt;

var t,i,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(t);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:55

Câu 8:

uses crt;

var n,m,i,t:integer;

begin

clrscr;

write('Nhap n='); readln(n);

write('Nhap m='); readln(m);

t:=0;

for i:=n to m do 

  if i mod 2=0 then t:=t+i;

writeln(t);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:55

Câu 10:

uses crt;

var n,m,i,t:integer;

begin

clrscr;

write('Nhap n='); readln(n);

write('Nhap m='); readln(m);

t:=0;

for i:=n to m do 

  if i mod 2=1 then t:=t+i;

writeln(t);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:55

Câu 12:

uses crt;

var n,m,i,t:integer;

begin

clrscr;

write('Nhap n='); readln(n);

write('Nhap m='); readln(m);

t:=0;

for i:=n to m do 

t:=t+i;

writeln(t);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:55

Câu 13:

uses crt;

var t,i,n:integer;

begin

clrscr;

write('Nhap n='); readln(n);

t:=0;

for i:=1 to n do

t:=t+i;

writeln(t);

readln;

end.

Bình luận (0)
Nguyễn Lê Phước Thịnh
14 tháng 4 2021 lúc 12:56

Câu 14:

uses crt;

var i,n: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.

Bình luận (0)

Các câu hỏi tương tự
Công danh
Xem chi tiết
thanh mai
Xem chi tiết
Trần Văn Tích
Xem chi tiết
Thái Trần
Xem chi tiết
Nguyễn Huỳnh Như
Xem chi tiết
Tuấn Phạm
Xem chi tiết
Trần Phương Thảo
Xem chi tiết
Tô Quốc
Xem chi tiết
Võ Ngọc Đan Kha
Xem chi tiết