vozForums
Báo lỗi diễn đàn và theo dõi tình hình khắc phục.

Go Back   vozForums > Máy tính để bàn > Phần mềm > Phát triển Phần mềm


Reply
 
Thread Tools
  #1  
Old 03-05-2010, 09:17
nguyengoctu's Avatar
nguyengoctu nguyengoctu is offline
Senior Member
 
Join Date: 09-2008
Location: CHXHCN................................................................................VN
Posts: 1,277
Send a message via MSN to nguyengoctu Send a message via Yahoo to nguyengoctu
Nhờ anh em giúp 1 bài về lập trình pascal,gấp lắm ạ ^^

giả sử có 1 vòng lặp như sau

for i:=1 to m do
for j:=1 to n do
begin
.....
end;
...

làm thế nào để chuyển vòng lặp đôi đó thành thủ tục đệ quy???
cảm ơn anh em



//cái ddth vắng tanh, post cả ngày rồi mà ko có ai reply,ae thông cảm
Reply With Quote
  #2  
Old 03-05-2010, 09:25
Lugiavn's Avatar
Lugiavn Lugiavn is offline
Senior Member
 
Join Date: 08-2006
Posts: 722
Re: Nhờ anh em giúp 1 bài về lập trình pascal,gấp lắm ạ ^^

Nói chung là bài tập này hơi nhảm.
Ko biết pascal, viết bằng C

PHP Code:
for_i(1);

void for_i(int i)
{
if (
<= m)
{
     
for_j(1);
     
for_i(1);
}
}

void for_j(int j)
{
if (
<= n)
{
     ....
     ....
     
for_j(1);
}


Last edited by Lugiavn; 03-05-2010 at 09:41.
Reply With Quote
  #3  
Old 03-05-2010, 09:37
nguyengoctu's Avatar
nguyengoctu nguyengoctu is offline
Senior Member
 
Join Date: 09-2008
Location: CHXHCN................................................................................VN
Posts: 1,277
Send a message via MSN to nguyengoctu Send a message via Yahoo to nguyengoctu
Re: Nhờ anh em giúp 1 bài về lập trình pascal,gấp lắm ạ ^^

Quote:
Originally Posted by Lugiavn View Post
Nói chung là bài tập này hơi nhảm.
Ko biết pascal, viết bằng C
PHP Code:
for_i(1);

void for_i(int i)
{
if (
<= m)
{
     
for_j(1);
     
for_i(1);
}
}

void for_j(int j)
{
if (
<= n)
{
     ....
     ....
     
for_j(1);
}

có thể đưa về 1 thủ tục đc ko ạ

up
Reply With Quote
  #4  
Old 03-05-2010, 09:41
Lugiavn's Avatar
Lugiavn Lugiavn is offline
Senior Member
 
Join Date: 08-2006
Posts: 722
Re: Nhờ anh em giúp 1 bài về lập trình pascal,gấp lắm ạ ^^

Thì bỏ 1 vòng for ra thôi.
Ví dụ

PHP Code:
for (int i 1 to m)
       
for_j(1);

void for_j(int j)
{
if (
<= n)
{
     ....
     ....
     
for_j(1);
}

Reply With Quote
  #5  
Old 03-05-2010, 09:49
nguyengoctu's Avatar
nguyengoctu nguyengoctu is offline
Senior Member
 
Join Date: 09-2008
Location: CHXHCN................................................................................VN
Posts: 1,277
Send a message via MSN to nguyengoctu Send a message via Yahoo to nguyengoctu
Re: Nhờ anh em giúp 1 bài về lập trình pascal,gấp lắm ạ ^^

Quote:
Originally Posted by Lugiavn View Post
Thì bỏ 1 vòng for ra thôi.
Ví dụ

PHP Code:
for (int i 1 to m)
       
for_j(1);

void for_j(int j)
{
if (
<= n)
{
     ....
     ....
     
for_j(1);
}

ngon rồi, thank bác
Reply With Quote
  #6  
Old 03-05-2010, 10:25
bacpp's Avatar
bacpp bacpp is offline
Senior Member
 
Join Date: 01-2010
Location: ?
Posts: 1,147
Re: Nhờ anh em giúp 1 bài về lập trình pascal,gấp lắm ạ ^^

Thế này dc ko?

Code:
procedure for_ij(i,j:interger)
begin
 ....
 if i<=m then
  begin
   if j<=n then for_ij(i,j+1);
  end;
 else for_ij(i+1,1);
end;
gọi for_ij(1,1)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump





All times are GMT +7. The time now is 19:54.


Steam Powered by vBulletin® 0.1 pre-alpha
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.