T
Tad J McClellan
["Followup-To:" header set to comp.lang.perl.misc.]
Yeah right.
That is a load of hooey.
You are not comparing languages, you are comparing algorithms.
If you had used the high water mark algorithm in C's (a), then it would have
generalized just as well as the high water mark algorithm in Perl's (a) did.
#define NUMMAX (10)
int max(int a[NUMMAX])
{
int max = a[0];
for(int i = 1; i < NUMMAX; i++)
if(a > max)
max = a;
return max;
}
sandeep said:Actually this is not a homework, I am just curious.
Yeah right.
Anyways, here is my solution:
(a) in C:
int max(int a, int b)
{
if(a>b)
return a;
return b;
}
in Perl:
sub max
{
my $max = shift;
for(@_) {
$max=$_ if($_>$max)
}
$max;
}
(b) in C:
#define NUMMAX (10)
int max(int a[NUMMAX])
{
int max = -1;
for(int i=0; i < NUMMAX
if(a[i++]>max)
max = a[i-1];
return max;
}
In Perl: the solution for (a) still works.
Conclusion: Perl is more expressive as a simple function for two arguments
often generalizes to any list.
That is a load of hooey.
You are not comparing languages, you are comparing algorithms.
If you had used the high water mark algorithm in C's (a), then it would have
generalized just as well as the high water mark algorithm in Perl's (a) did.
#define NUMMAX (10)
int max(int a[NUMMAX])
{
int max = a[0];
for(int i = 1; i < NUMMAX; i++)
if(a > max)
max = a;
return max;
}