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

Go Back   vozForums > Khu vui chơi giải trí > Chuyện trò linh tinh™

Reply
 
Thread Tools
  #1  
Old 27-11-2010, 11:01
pt_trieu's Avatar
pt_trieu pt_trieu is offline
Senior Member
 
Join Date: 10-2009
Location: /root/
Posts: 222
Send a message via Yahoo to pt_trieu
Hỏi bài đệ quy C tìm max trong mảng

Đề bài đơn giản chỉ là tìm phần tử lớn nhất của mảng a có n phần tử. Mỗi tội là cả kỳ em đi học được có 2 buổi. Các bác giúp em với sắp thi rồi :(

Trong vở có ghi là:
Code:
max(a,n-1)>a[n]?max(a,n-1):a[n];
Không biết lúc code khai báo cái hàm max kiểm gì luôn.
Reply With Quote
  #2  
Old 27-11-2010, 11:15
xonglennao's Avatar
xonglennao xonglennao is offline
Senior Member
 
Join Date: 11-2007
Posts: 358
Re: Hỏi bài đệ quy C tìm max trong mảng

Bạn khai báo thế này nè

int max(int a[],int n)
{
if(n==1) return a[0];
else
return max(a,n-1)>a[n-1]?max(a,n-1):a[n-1];
}
Reply With Quote
  #3  
Old 27-11-2010, 11:45
pt_trieu's Avatar
pt_trieu pt_trieu is offline
Senior Member
 
Join Date: 10-2009
Location: /root/
Posts: 222
Send a message via Yahoo to pt_trieu
Re: Hỏi bài đệ quy C tìm max trong mảng

int a[]=5,6,7,2,7,9;
int n=6;
Thế mình gọi hàm max kìa là
max(a,n);
thế này hả bạn ?
Reply With Quote
  #4  
Old 27-11-2010, 12:45
xonglennao's Avatar
xonglennao xonglennao is offline
Senior Member
 
Join Date: 11-2007
Posts: 358
Re: Hỏi bài đệ quy C tìm max trong mảng

Quote:
Originally Posted by pt_trieu View Post
int a[]=5,6,7,2,7,9;
int n=6;
Thế mình gọi hàm max kìa là
max(a,n);
thế này hả bạn ?
Đúng rồi bạn à . n là số phần tử của mảng .
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 00:57.


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