WeixiangYan/CodeTransOcean huggingface dataset:
Task: Jensen's Device



C#: using System;

class JensensDevice
{    
    public static double Sum(ref int i, int lo, int hi, Func<double> term)
    {
        double temp = 0.0;
        for (i = lo; i <= hi; i++)
        {
            temp += term();
        }
        return temp;
    }

    static void Main()
    {
        int i = 0;
        Console.WriteLine(Sum(ref i, 1, 100, () => 1.0 / i));
    }
}









Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Jensen_Device is
   function Sum
            (  I : not null access Float;
               Lo, Hi : Float;
               F : access function return Float
            )  return Float is
      Temp : Float := 0.0;
   begin
      I.all := Lo;
      while I.all <= Hi loop
         Temp := Temp + F.all;
         I.all := I.all + 1.0;
      end loop;
      return Temp;
   end Sum;

   I : aliased Float;
   function Inv_I return Float is
   begin
      return 1.0 / I;
   end Inv_I;
begin
   Put_Line (Float'Image (Sum (I'Access, 1.0, 100.0, Inv_I'Access)));
end Jensen_Device;
Task: Jensen's Device

C: #include <stdio.h>

int i;
double sum(int *i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (*i = lo; *i <= hi; (*i)++)
        temp += term();
    return temp;
}

double term_func() { return 1.0 / i; }

int main () {
    printf("%f\n", sum(&i, 1, 100, term_func));
    return 0;
}











Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Jensen_Device is
   function Sum
            (  I : not null access Float;
               Lo, Hi : Float;
               F : access function return Float
            )  return Float is
      Temp : Float := 0.0;
   begin
      I.all := Lo;
      while I.all <= Hi loop
         Temp := Temp + F.all;
         I.all := I.all + 1.0;
      end loop;
      return Temp;
   end Sum;

   I : aliased Float;
   function Inv_I return Float is
   begin
      return 1.0 / I;
   end Inv_I;
begin
   Put_Line (Float'Image (Sum (I'Access, 1.0, 100.0, Inv_I'Access)));
end Jensen_Device;
Task: Jensen's Device


C++: #include <iostream>

#define SUM(i,lo,hi,term)\
[&](const int _lo,const int _hi){\
  decltype(+(term)) sum{};\
  for (i = _lo; i <= _hi; ++i) sum += (term);\
  return sum;\
}((lo),(hi))

int i;
double sum(int &i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (i = lo; i <= hi; i++)
        temp += term();
    return temp;
}
double term_func() { return 1.0 / i; }

int main () {
    std::cout << sum(i, 1, 100, term_func) << std::endl;
    std::cout << SUM(i,1,100,1.0/i) << "\n";
    return 0;
}










Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Jensen_Device is
   function Sum
            (  I : not null access Float;
               Lo, Hi : Float;
               F : access function return Float
            )  return Float is
      Temp : Float := 0.0;
   begin
      I.all := Lo;
      while I.all <= Hi loop
         Temp := Temp + F.all;
         I.all := I.all + 1.0;
      end loop;
      return Temp;
   end Sum;

   I : aliased Float;
   function Inv_I return Float is
   begin
      return 1.0 / I;
   end Inv_I;
begin
   Put_Line (Float'Image (Sum (I'Access, 1.0, 100.0, Inv_I'Access)));
end Jensen_Device;
Task: Jensen's Device




Go: package main

import "fmt"

var i int

func sum(i *int, lo, hi int, term func() float64) float64 {
    temp := 0.0
    for *i = lo; *i <= hi; (*i)++ {
        temp += term()
    }
    return temp
}

func main() {
    fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) }))
}








Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Jensen_Device is
   function Sum
            (  I : not null access Float;
               Lo, Hi : Float;
               F : access function return Float
            )  return Float is
      Temp : Float := 0.0;
   begin
      I.all := Lo;
      while I.all <= Hi loop
         Temp := Temp + F.all;
         I.all := I.all + 1.0;
      end loop;
      return Temp;
   end Sum;

   I : aliased Float;
   function Inv_I return Float is
   begin
      return 1.0 / I;
   end Inv_I;
begin
   Put_Line (Float'Image (Sum (I'Access, 1.0, 100.0, Inv_I'Access)));
end Jensen_Device;
Task: Jensen's Device





Java: import java.util.function.*;
import java.util.stream.*;

public class Jensen {
    static double sum(int lo, int hi, IntToDoubleFunction f) {
        return IntStream.rangeClosed(lo, hi).mapToDouble(f).sum();
    }
        
    public static void main(String args[]) {
        System.out.println(sum(1, 100, (i -> 1.0/i)));
    }
}







Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Jensen_Device is
   function Sum
            (  I : not null access Float;
               Lo, Hi : Float;
               F : access function return Float
            )  return Float is
      Temp : Float := 0.0;
   begin
      I.all := Lo;
      while I.all <= Hi loop
         Temp := Temp + F.all;
         I.all := I.all + 1.0;
      end loop;
      return Temp;
   end Sum;

   I : aliased Float;
   function Inv_I return Float is
   begin
      return 1.0 / I;
   end Inv_I;
begin
   Put_Line (Float'Image (Sum (I'Access, 1.0, 100.0, Inv_I'Access)));
end Jensen_Device;
Task: Jensen's Device







Python: class Ref(object):
    def __init__(self, value=None):
        self.value = value

def harmonic_sum(i, lo, hi, term):
    
    temp = 0
    i.value = lo
    while i.value <= hi:  
        temp += term() 
        i.value += 1   
    return temp

i = Ref()



print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)





Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Jensen_Device is
   function Sum
            (  I : not null access Float;
               Lo, Hi : Float;
               F : access function return Float
            )  return Float is
      Temp : Float := 0.0;
   begin
      I.all := Lo;
      while I.all <= Hi loop
         Temp := Temp + F.all;
         I.all := I.all + 1.0;
      end loop;
      return Temp;
   end Sum;

   I : aliased Float;
   function Inv_I return Float is
   begin
      return 1.0 / I;
   end Inv_I;
begin
   Put_Line (Float'Image (Sum (I'Access, 1.0, 100.0, Inv_I'Access)));
end Jensen_Device;
Task: Jensen's Device








VB: Private Function sum(i As String, ByVal lo As Integer, ByVal hi As Integer, term As String) As Double
    Dim temp As Double
    For k = lo To hi
        temp = temp + Evaluate(Replace(term, i, k))
    Next k
    sum = temp
End Function
Sub Jensen_Device()
    Debug.Print sum("i", 1, 100, "1/i")
    Debug.Print sum("i", 1, 100, "i*i")
    Debug.Print sum("j", 1, 100, "sin(j)")
End Sub




Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Jensen_Device is
   function Sum
            (  I : not null access Float;
               Lo, Hi : Float;
               F : access function return Float
            )  return Float is
      Temp : Float := 0.0;
   begin
      I.all := Lo;
      while I.all <= Hi loop
         Temp := Temp + F.all;
         I.all := I.all + 1.0;
      end loop;
      return Temp;
   end Sum;

   I : aliased Float;
   function Inv_I return Float is
   begin
      return 1.0 / I;
   end Inv_I;
begin
   Put_Line (Float'Image (Sum (I'Access, 1.0, 100.0, Inv_I'Access)));
end Jensen_Device;
Task: Jensen's Device

C: #include <stdio.h>

int i;
double sum(int *i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (*i = lo; *i <= hi; (*i)++)
        temp += term();
    return temp;
}

double term_func() { return 1.0 / i; }

int main () {
    printf("%f\n", sum(&i, 1, 100, term_func));
    return 0;
}
Task: Jensen's Device



C#: using System;

class JensensDevice
{    
    public static double Sum(ref int i, int lo, int hi, Func<double> term)
    {
        double temp = 0.0;
        for (i = lo; i <= hi; i++)
        {
            temp += term();
        }
        return temp;
    }

    static void Main()
    {
        int i = 0;
        Console.WriteLine(Sum(ref i, 1, 100, () => 1.0 / i));
    }
}
Task: Jensen's Device


C++: #include <iostream>

#define SUM(i,lo,hi,term)\
[&](const int _lo,const int _hi){\
  decltype(+(term)) sum{};\
  for (i = _lo; i <= _hi; ++i) sum += (term);\
  return sum;\
}((lo),(hi))

int i;
double sum(int &i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (i = lo; i <= hi; i++)
        temp += term();
    return temp;
}
double term_func() { return 1.0 / i; }

int main () {
    std::cout << sum(i, 1, 100, term_func) << std::endl;
    std::cout << SUM(i,1,100,1.0/i) << "\n";
    return 0;
}
Task: Jensen's Device





Java: import java.util.function.*;
import java.util.stream.*;

public class Jensen {
    static double sum(int lo, int hi, IntToDoubleFunction f) {
        return IntStream.rangeClosed(lo, hi).mapToDouble(f).sum();
    }
        
    public static void main(String args[]) {
        System.out.println(sum(1, 100, (i -> 1.0/i)));
    }
}
Task: Jensen's Device







Python: class Ref(object):
    def __init__(self, value=None):
        self.value = value

def harmonic_sum(i, lo, hi, term):
    
    temp = 0
    i.value = lo
    while i.value <= hi:  
        temp += term() 
        i.value += 1   
    return temp

i = Ref()



print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)
Task: Jensen's Device








VB: Private Function sum(i As String, ByVal lo As Integer, ByVal hi As Integer, term As String) As Double
    Dim temp As Double
    For k = lo To hi
        temp = temp + Evaluate(Replace(term, i, k))
    Next k
    sum = temp
End Function
Sub Jensen_Device()
    Debug.Print sum("i", 1, 100, "1/i")
    Debug.Print sum("i", 1, 100, "i*i")
    Debug.Print sum("j", 1, 100, "sin(j)")
End Sub
Task: Jensen's Device




Go: package main

import "fmt"

var i int

func sum(i *int, lo, hi int, term func() float64) float64 {
    temp := 0.0
    for *i = lo; *i <= hi; (*i)++ {
        temp += term()
    }
    return temp
}

func main() {
    fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) }))
}
Task: Jensen's Device



C#: using System;

class JensensDevice
{    
    public static double Sum(ref int i, int lo, int hi, Func<double> term)
    {
        double temp = 0.0;
        for (i = lo; i <= hi; i++)
        {
            temp += term();
        }
        return temp;
    }

    static void Main()
    {
        int i = 0;
        Console.WriteLine(Sum(ref i, 1, 100, () => 1.0 / i));
    }
}








Fortran:       FUNCTION SUM(I,LO,HI,TERM)
        SUM = 0
        DO I = LO,HI
          SUM = SUM + TERM
        END DO
      END FUNCTION SUM
      WRITE (6,*) SUM(I,1,100,1.0/I)
      END
Task: Jensen's Device


C++: #include <iostream>

#define SUM(i,lo,hi,term)\
[&](const int _lo,const int _hi){\
  decltype(+(term)) sum{};\
  for (i = _lo; i <= _hi; ++i) sum += (term);\
  return sum;\
}((lo),(hi))

int i;
double sum(int &i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (i = lo; i <= hi; i++)
        temp += term();
    return temp;
}
double term_func() { return 1.0 / i; }

int main () {
    std::cout << sum(i, 1, 100, term_func) << std::endl;
    std::cout << SUM(i,1,100,1.0/i) << "\n";
    return 0;
}









Fortran:       FUNCTION SUM(I,LO,HI,TERM)
        SUM = 0
        DO I = LO,HI
          SUM = SUM + TERM
        END DO
      END FUNCTION SUM
      WRITE (6,*) SUM(I,1,100,1.0/I)
      END
Task: Jensen's Device

C: #include <stdio.h>

int i;
double sum(int *i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (*i = lo; *i <= hi; (*i)++)
        temp += term();
    return temp;
}

double term_func() { return 1.0 / i; }

int main () {
    printf("%f\n", sum(&i, 1, 100, term_func));
    return 0;
}










Fortran:       FUNCTION SUM(I,LO,HI,TERM)
        SUM = 0
        DO I = LO,HI
          SUM = SUM + TERM
        END DO
      END FUNCTION SUM
      WRITE (6,*) SUM(I,1,100,1.0/I)
      END
Task: Jensen's Device





Java: import java.util.function.*;
import java.util.stream.*;

public class Jensen {
    static double sum(int lo, int hi, IntToDoubleFunction f) {
        return IntStream.rangeClosed(lo, hi).mapToDouble(f).sum();
    }
        
    public static void main(String args[]) {
        System.out.println(sum(1, 100, (i -> 1.0/i)));
    }
}






Fortran:       FUNCTION SUM(I,LO,HI,TERM)
        SUM = 0
        DO I = LO,HI
          SUM = SUM + TERM
        END DO
      END FUNCTION SUM
      WRITE (6,*) SUM(I,1,100,1.0/I)
      END
Task: Jensen's Device







Python: class Ref(object):
    def __init__(self, value=None):
        self.value = value

def harmonic_sum(i, lo, hi, term):
    
    temp = 0
    i.value = lo
    while i.value <= hi:  
        temp += term() 
        i.value += 1   
    return temp

i = Ref()



print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)




Fortran:       FUNCTION SUM(I,LO,HI,TERM)
        SUM = 0
        DO I = LO,HI
          SUM = SUM + TERM
        END DO
      END FUNCTION SUM
      WRITE (6,*) SUM(I,1,100,1.0/I)
      END
Task: Jensen's Device








VB: Private Function sum(i As String, ByVal lo As Integer, ByVal hi As Integer, term As String) As Double
    Dim temp As Double
    For k = lo To hi
        temp = temp + Evaluate(Replace(term, i, k))
    Next k
    sum = temp
End Function
Sub Jensen_Device()
    Debug.Print sum("i", 1, 100, "1/i")
    Debug.Print sum("i", 1, 100, "i*i")
    Debug.Print sum("j", 1, 100, "sin(j)")
End Sub



Fortran:       FUNCTION SUM(I,LO,HI,TERM)
        SUM = 0
        DO I = LO,HI
          SUM = SUM + TERM
        END DO
      END FUNCTION SUM
      WRITE (6,*) SUM(I,1,100,1.0/I)
      END
Task: Jensen's Device






PHP: $i;
function sum (&$i, $lo, $hi, $term) {
    $temp = 0;
    for ($i = $lo; $i <= $hi; $i++) {
        $temp += $term();
    }
    return $temp;
}

echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";


function sum ($lo,$hi)
{
 $temp = 0;
 for ($i = $lo; $i <= $hi; $i++)
 {
  $temp += (1 / $i);
 }
 return $temp;
}
echo sum(1,100);






Fortran:       FUNCTION SUM(I,LO,HI,TERM)
        SUM = 0
        DO I = LO,HI
          SUM = SUM + TERM
        END DO
      END FUNCTION SUM
      WRITE (6,*) SUM(I,1,100,1.0/I)
      END
Task: Jensen's Device






PHP: $i;
function sum (&$i, $lo, $hi, $term) {
    $temp = 0;
    for ($i = $lo; $i <= $hi; $i++) {
        $temp += $term();
    }
    return $temp;
}

echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";


function sum ($lo,$hi)
{
 $temp = 0;
 for ($i = $lo; $i <= $hi; $i++)
 {
  $temp += (1 / $i);
 }
 return $temp;
}
echo sum(1,100);
Task: Jensen's Device






PHP: $i;
function sum (&$i, $lo, $hi, $term) {
    $temp = 0;
    for ($i = $lo; $i <= $hi; $i++) {
        $temp += $term();
    }
    return $temp;
}

echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";


function sum ($lo,$hi)
{
 $temp = 0;
 for ($i = $lo; $i <= $hi; $i++)
 {
  $temp += (1 / $i);
 }
 return $temp;
}
echo sum(1,100);







Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Jensen_Device is
   function Sum
            (  I : not null access Float;
               Lo, Hi : Float;
               F : access function return Float
            )  return Float is
      Temp : Float := 0.0;
   begin
      I.all := Lo;
      while I.all <= Hi loop
         Temp := Temp + F.all;
         I.all := I.all + 1.0;
      end loop;
      return Temp;
   end Sum;

   I : aliased Float;
   function Inv_I return Float is
   begin
      return 1.0 / I;
   end Inv_I;
begin
   Put_Line (Float'Image (Sum (I'Access, 1.0, 100.0, Inv_I'Access)));
end Jensen_Device;
Task: Greatest element of a list



C#: int[] values = new int[] {1,2,3,4,5,6,7,8,9,10};

int max = values.Max();









Ada: with Ada.Text_Io;

procedure Max_Test isco
   
   type Flt_Array is array (Natural range <>) of Float;
   
   
   Empty_Array : Exception;
   
   function Max(Item : Flt_Array) return Float is
      Max_Element : Float := Float'First;
   begin
      if Item'Length = 0 then 
         raise Empty_Array;
      end if;
  
      for I in Item'range loop
         if Item(I) > Max_Element then
            Max_Element := Item(I);
         end if;
      end loop;
      return Max_Element;
   end Max;
    
   Buf : Flt_Array := (-275.0, -111.19, 0.0, -1234568.0, 3.14159, -3.14159);
begin
   Ada.Text_IO.Put_Line(Float'Image(Max(Buf)));
end Max_Test;
Task: Greatest element of a list

C: #include <assert.h>

float max(unsigned int count, float values[]) {
     assert(count > 0);
     size_t idx;
     float themax = values[0];
     for(idx = 1; idx < count; ++idx) {
          themax = values[idx] > themax ? values[idx] : themax;
     }
     return themax;
}











Ada: with Ada.Text_Io;

procedure Max_Test isco
   
   type Flt_Array is array (Natural range <>) of Float;
   
   
   Empty_Array : Exception;
   
   function Max(Item : Flt_Array) return Float is
      Max_Element : Float := Float'First;
   begin
      if Item'Length = 0 then 
         raise Empty_Array;
      end if;
  
      for I in Item'range loop
         if Item(I) > Max_Element then
            Max_Element := Item(I);
         end if;
      end loop;
      return Max_Element;
   end Max;
    
   Buf : Flt_Array := (-275.0, -111.19, 0.0, -1234568.0, 3.14159, -3.14159);
begin
   Ada.Text_IO.Put_Line(Float'Image(Max(Buf)));
end Max_Test;
Task: Greatest element of a list


C++: #include <algorithm>  
#include <iterator>   
#include <functional> 

template<class It, class Comp = std::less<>>
    
constexpr auto max_value(It first, It last, Comp compare = std::less{})
{
    
    return *std::max_element(first, last, compare);
}

template<class C, class Comp = std::less<>>
    
constexpr auto max_value(const C& container, Comp compare = std::less{})
{
    
    using std::begin; using std::end;
    return max_value(begin(container), end(container), compare);
}










Ada: with Ada.Text_Io;

procedure Max_Test isco
   
   type Flt_Array is array (Natural range <>) of Float;
   
   
   Empty_Array : Exception;
   
   function Max(Item : Flt_Array) return Float is
      Max_Element : Float := Float'First;
   begin
      if Item'Length = 0 then 
         raise Empty_Array;
      end if;
  
      for I in Item'range loop
         if Item(I) > Max_Element then
            Max_Element := Item(I);
         end if;
      end loop;
      return Max_Element;
   end Max;
    
   Buf : Flt_Array := (-275.0, -111.19, 0.0, -1234568.0, 3.14159, -3.14159);
begin
   Ada.Text_IO.Put_Line(Float'Image(Max(Buf)));
end Max_Test;
Task: Greatest element of a list




Go: package main

import (
    "fmt"

    "github.com/gonum/floats"
)

func main() {
	fmt.Println(floats.Max([]float64{63, 70, 37, 34, 83, 27, 19, 97, 9, 17})) 
	fmt.Println(floats.Min([]float64{63, 70, 37, 34, 83, 27, 19, 97, 9, 17})) 
}








Ada: with Ada.Text_Io;

procedure Max_Test isco
   
   type Flt_Array is array (Natural range <>) of Float;
   
   
   Empty_Array : Exception;
   
   function Max(Item : Flt_Array) return Float is
      Max_Element : Float := Float'First;
   begin
      if Item'Length = 0 then 
         raise Empty_Array;
      end if;
  
      for I in Item'range loop
         if Item(I) > Max_Element then
            Max_Element := Item(I);
         end if;
      end loop;
      return Max_Element;
   end Max;
    
   Buf : Flt_Array := (-275.0, -111.19, 0.0, -1234568.0, 3.14159, -3.14159);
begin
   Ada.Text_IO.Put_Line(Float'Image(Max(Buf)));
end Max_Test;
Task: Greatest element of a list





Java: public static float max(float[] values) throws NoSuchElementException {
    if (values.length == 0)
        throw new NoSuchElementException();
    float themax = values[0];
    for (int idx = 1; idx < values.length; ++idx) {
        if (values[idx] > themax)
            themax = values[idx];
    }
    return themax;
}







Ada: with Ada.Text_Io;

procedure Max_Test isco
   
   type Flt_Array is array (Natural range <>) of Float;
   
   
   Empty_Array : Exception;
   
   function Max(Item : Flt_Array) return Float is
      Max_Element : Float := Float'First;
   begin
      if Item'Length = 0 then 
         raise Empty_Array;
      end if;
  
      for I in Item'range loop
         if Item(I) > Max_Element then
            Max_Element := Item(I);
         end if;
      end loop;
      return Max_Element;
   end Max;
    
   Buf : Flt_Array := (-275.0, -111.19, 0.0, -1234568.0, 3.14159, -3.14159);
begin
   Ada.Text_IO.Put_Line(Float'Image(Max(Buf)));
end Max_Test;
Task: Greatest element of a list







Python: max(values)





Ada: with Ada.Text_Io;

procedure Max_Test isco
   
   type Flt_Array is array (Natural range <>) of Float;
   
   
   Empty_Array : Exception;
   
   function Max(Item : Flt_Array) return Float is
      Max_Element : Float := Float'First;
   begin
      if Item'Length = 0 then 
         raise Empty_Array;
      end if;
  
      for I in Item'range loop
         if Item(I) > Max_Element then
            Max_Element := Item(I);
         end if;
      end loop;
      return Max_Element;
   end Max;
    
   Buf : Flt_Array := (-275.0, -111.19, 0.0, -1234568.0, 3.14159, -3.14159);
begin
   Ada.Text_IO.Put_Line(Float'Image(Max(Buf)));
end Max_Test;
Task: Greatest element of a list








VB: functioni FindMax(...) as double
    dim x as integer
        
    for x = 1 to ParamValCount
        IF ParamVal(x) > Result THEN Result = ParamVal(x)
    next
End functioni

Print FindMax(50, 20, 65, 20, 105)




Ada: with Ada.Text_Io;

procedure Max_Test isco
   
   type Flt_Array is array (Natural range <>) of Float;
   
   
   Empty_Array : Exception;
   
   function Max(Item : Flt_Array) return Float is
      Max_Element : Float := Float'First;
   begin
      if Item'Length = 0 then 
         raise Empty_Array;
      end if;
  
      for I in Item'range loop
         if Item(I) > Max_Element then
            Max_Element := Item(I);
         end if;
      end loop;
      return Max_Element;
   end Max;
    
   Buf : Flt_Array := (-275.0, -111.19, 0.0, -1234568.0, 3.14159, -3.14159);
begin
   Ada.Text_IO.Put_Line(Float'Image(Max(Buf)));
end Max_Test;
Task: Greatest element of a list

C: #include <assert.h>

float max(unsigned int count, float values[]) {
     assert(count > 0);
     size_t idx;
     float themax = values[0];
     for(idx = 1; idx < count; ++idx) {
          themax = values[idx] > themax ? values[idx] : themax;
     }
     return themax;
}
Task: Greatest element of a list



C#: int[] values = new int[] {1,2,3,4,5,6,7,8,9,10};

int max = values.Max();
Task: Greatest element of a list


C++: #include <algorithm>  
#include <iterator>   
#include <functional> 

template<class It, class Comp = std::less<>>
    
constexpr auto max_value(It first, It last, Comp compare = std::less{})
{
    
    return *std::max_element(first, last, compare);
}

template<class C, class Comp = std::less<>>
    
constexpr auto max_value(const C& container, Comp compare = std::less{})
{
    
    using std::begin; using std::end;
    return max_value(begin(container), end(container), compare);
}
Task: Greatest element of a list





Java: public static float max(float[] values) throws NoSuchElementException {
    if (values.length == 0)
        throw new NoSuchElementException();
    float themax = values[0];
    for (int idx = 1; idx < values.length; ++idx) {
        if (values[idx] > themax)
            themax = values[idx];
    }
    return themax;
}
Task: Greatest element of a list








VB: functioni FindMax(...) as double
    dim x as integer
        
    for x = 1 to ParamValCount
        IF ParamVal(x) > Result THEN Result = ParamVal(x)
    next
End functioni

Print FindMax(50, 20, 65, 20, 105)
Task: Greatest element of a list




Go: package main

import (
    "fmt"

    "github.com/gonum/floats"
)

func main() {
	fmt.Println(floats.Max([]float64{63, 70, 37, 34, 83, 27, 19, 97, 9, 17})) 
	fmt.Println(floats.Min([]float64{63, 70, 37, 34, 83, 27, 19, 97, 9, 17})) 
}
Task: Greatest element of a list







Python: max(values)
Task: Greatest element of a list



C#: int[] values = new int[] {1,2,3,4,5,6,7,8,9,10};

int max = values.Max();








Fortran: program test_maxval
 
integer,dimension(5),parameter :: x = [10,100,7,1,2]
real,dimension(5),parameter :: y = [5.0,60.0,1.0,678.0,0.0]
 
write(*,'(I5)') maxval(x)
write(*,'(F5.1)') maxval(y)

end program test_maxval