WeixiangYan/CodeTransOcean huggingface dataset:
Task: Infinity


C++: #include <limits>

double inf()
{
  if (std::numeric_limits<double>::has_infinity)
    return std::numeric_limits<double>::infinity();
  else
    return std::numeric_limits<double>::max();
}










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

procedure Infinities is
   function Sup return Float is 
      Result : Float := Float'Last;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Succ (Result);
      end if;
      return Result;
   end Sup;

   function Inf return Float is 
      Result : Float := Float'First;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Pred (Result);
      end if;
      return Result;
   end Inf;
begin
   Put_Line ("Supremum" & Float'Image (Sup));
   Put_Line ("Infimum " & Float'Image (Inf));
end Infinities;
Task: Infinity




Go: package main

import (
    "fmt"
    "math"
)


func posInf() float64 {
    return math.Inf(1) 
}

func main() {
    x := 1.5 
    
    
    x = posInf()                     
    fmt.Println(x, math.IsInf(x, 1)) 
}








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

procedure Infinities is
   function Sup return Float is 
      Result : Float := Float'Last;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Succ (Result);
      end if;
      return Result;
   end Sup;

   function Inf return Float is 
      Result : Float := Float'First;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Pred (Result);
      end if;
      return Result;
   end Inf;
begin
   Put_Line ("Supremum" & Float'Image (Sup));
   Put_Line ("Infimum " & Float'Image (Inf));
end Infinities;
Task: Infinity





Java: double infinity = Double.POSITIVE_INFINITY; 
Double.isInfinite(infinity); 







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

procedure Infinities is
   function Sup return Float is 
      Result : Float := Float'Last;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Succ (Result);
      end if;
      return Result;
   end Sup;

   function Inf return Float is 
      Result : Float := Float'First;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Pred (Result);
      end if;
      return Result;
   end Inf;
begin
   Put_Line ("Supremum" & Float'Image (Sup));
   Put_Line ("Infimum " & Float'Image (Inf));
end Infinities;
Task: Infinity







Python: >>> float('infinity')
inf





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

procedure Infinities is
   function Sup return Float is 
      Result : Float := Float'Last;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Succ (Result);
      end if;
      return Result;
   end Sup;

   function Inf return Float is 
      Result : Float := Float'First;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Pred (Result);
      end if;
      return Result;
   end Inf;
begin
   Put_Line ("Supremum" & Float'Image (Sup));
   Put_Line ("Infimum " & Float'Image (Inf));
end Infinities;
Task: Infinity








VB: Declare CustomType Library "inf"
    Function inf#
End Declare

Print inf




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

procedure Infinities is
   function Sup return Float is 
      Result : Float := Float'Last;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Succ (Result);
      end if;
      return Result;
   end Sup;

   function Inf return Float is 
      Result : Float := Float'First;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Pred (Result);
      end if;
      return Result;
   end Inf;
begin
   Put_Line ("Supremum" & Float'Image (Sup));
   Put_Line ("Infimum " & Float'Image (Inf));
end Infinities;
Task: Infinity

C: #include <math.h>	
#include <stdio.h>	

double inf(void) {
  return HUGE_VAL;
}

int main() {
  printf("%g\n", inf());
  return 0;
}
Task: Infinity



C#: using System;

class Program
{
    static double PositiveInfinity()
    {
        return double.PositiveInfinity;
    }

    static void Main()
    {
        Console.WriteLine(PositiveInfinity());
    }
}
Task: Infinity


C++: #include <limits>

double inf()
{
  if (std::numeric_limits<double>::has_infinity)
    return std::numeric_limits<double>::infinity();
  else
    return std::numeric_limits<double>::max();
}
Task: Infinity




Go: package main

import (
    "fmt"
    "math"
)


func posInf() float64 {
    return math.Inf(1) 
}

func main() {
    x := 1.5 
    
    
    x = posInf()                     
    fmt.Println(x, math.IsInf(x, 1)) 
}
Task: Infinity





Java: double infinity = Double.POSITIVE_INFINITY; 
Double.isInfinite(infinity);
Task: Infinity







Python: >>> float('infinity')
inf
Task: Infinity








VB: Declare CustomType Library "inf"
    Function inf#
End Declare

Print inf
Task: Infinity



C#: using System;

class Program
{
    static double PositiveInfinity()
    {
        return double.PositiveInfinity;
    }

    static void Main()
    {
        Console.WriteLine(PositiveInfinity());
    }
}








Fortran: program to_f_the_ineffable
   use, intrinsic :: ieee_arithmetic
   integer :: i
   real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
   
   do i = 1, 2
      if (ieee_support_datatype(x(i))) then
         if (ieee_is_finite(x(i))) then
            print *, 'x(',i,') is finite'
         else
            print *, 'x(',i,') is infinite'
         end if
         
      else
         print *, 'x(',i,') is not in an IEEE-supported format'
      end if
   end do
end program to_f_the_ineffable
Task: Infinity


C++: #include <limits>

double inf()
{
  if (std::numeric_limits<double>::has_infinity)
    return std::numeric_limits<double>::infinity();
  else
    return std::numeric_limits<double>::max();
}









Fortran: program to_f_the_ineffable
   use, intrinsic :: ieee_arithmetic
   integer :: i
   real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
   
   do i = 1, 2
      if (ieee_support_datatype(x(i))) then
         if (ieee_is_finite(x(i))) then
            print *, 'x(',i,') is finite'
         else
            print *, 'x(',i,') is infinite'
         end if
         
      else
         print *, 'x(',i,') is not in an IEEE-supported format'
      end if
   end do
end program to_f_the_ineffable
Task: Infinity

C: #include <math.h>	
#include <stdio.h>	

double inf(void) {
  return HUGE_VAL;
}

int main() {
  printf("%g\n", inf());
  return 0;
}










Fortran: program to_f_the_ineffable
   use, intrinsic :: ieee_arithmetic
   integer :: i
   real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
   
   do i = 1, 2
      if (ieee_support_datatype(x(i))) then
         if (ieee_is_finite(x(i))) then
            print *, 'x(',i,') is finite'
         else
            print *, 'x(',i,') is infinite'
         end if
         
      else
         print *, 'x(',i,') is not in an IEEE-supported format'
      end if
   end do
end program to_f_the_ineffable
Task: Infinity




Go: package main

import (
    "fmt"
    "math"
)


func posInf() float64 {
    return math.Inf(1) 
}

func main() {
    x := 1.5 
    
    
    x = posInf()                     
    fmt.Println(x, math.IsInf(x, 1)) 
}







Fortran: program to_f_the_ineffable
   use, intrinsic :: ieee_arithmetic
   integer :: i
   real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
   
   do i = 1, 2
      if (ieee_support_datatype(x(i))) then
         if (ieee_is_finite(x(i))) then
            print *, 'x(',i,') is finite'
         else
            print *, 'x(',i,') is infinite'
         end if
         
      else
         print *, 'x(',i,') is not in an IEEE-supported format'
      end if
   end do
end program to_f_the_ineffable
Task: Infinity





Java: double infinity = Double.POSITIVE_INFINITY; 
Double.isInfinite(infinity); 






Fortran: program to_f_the_ineffable
   use, intrinsic :: ieee_arithmetic
   integer :: i
   real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
   
   do i = 1, 2
      if (ieee_support_datatype(x(i))) then
         if (ieee_is_finite(x(i))) then
            print *, 'x(',i,') is finite'
         else
            print *, 'x(',i,') is infinite'
         end if
         
      else
         print *, 'x(',i,') is not in an IEEE-supported format'
      end if
   end do
end program to_f_the_ineffable
Task: Infinity







Python: >>> float('infinity')
inf




Fortran: program to_f_the_ineffable
   use, intrinsic :: ieee_arithmetic
   integer :: i
   real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
   
   do i = 1, 2
      if (ieee_support_datatype(x(i))) then
         if (ieee_is_finite(x(i))) then
            print *, 'x(',i,') is finite'
         else
            print *, 'x(',i,') is infinite'
         end if
         
      else
         print *, 'x(',i,') is not in an IEEE-supported format'
      end if
   end do
end program to_f_the_ineffable
Task: Infinity








VB: Declare CustomType Library "inf"
    Function inf#
End Declare

Print inf



Fortran: program to_f_the_ineffable
   use, intrinsic :: ieee_arithmetic
   integer :: i
   real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
   
   do i = 1, 2
      if (ieee_support_datatype(x(i))) then
         if (ieee_is_finite(x(i))) then
            print *, 'x(',i,') is finite'
         else
            print *, 'x(',i,') is infinite'
         end if
         
      else
         print *, 'x(',i,') is not in an IEEE-supported format'
      end if
   end do
end program to_f_the_ineffable
Task: Infinity






PHP: INF





Fortran: program to_f_the_ineffable
   use, intrinsic :: ieee_arithmetic
   integer :: i
   real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
   
   do i = 1, 2
      if (ieee_support_datatype(x(i))) then
         if (ieee_is_finite(x(i))) then
            print *, 'x(',i,') is finite'
         else
            print *, 'x(',i,') is infinite'
         end if
         
      else
         print *, 'x(',i,') is not in an IEEE-supported format'
      end if
   end do
end program to_f_the_ineffable
Task: Infinity






PHP: INF






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

procedure Infinities is
   function Sup return Float is 
      Result : Float := Float'Last;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Succ (Result);
      end if;
      return Result;
   end Sup;

   function Inf return Float is 
      Result : Float := Float'First;
   begin
      if not Float'Machine_Overflows then
         Result := Float'Pred (Result);
      end if;
      return Result;
   end Inf;
begin
   Put_Line ("Supremum" & Float'Image (Sup));
   Put_Line ("Infimum " & Float'Image (Inf));
end Infinities;
Task: Infinity






PHP: INF
Task: Sort an integer array



C#: using System;
using System.Collections.Generic;

public class Program {
    static void Main() {
        int[] unsorted = { 6, 2, 7, 8, 3, 1, 10, 5, 4, 9 };
        Array.Sort(unsorted);
    }
}









Ada: with Gnat.Heap_Sort_G;
 
procedure Integer_Sort is
   
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Move_Int(From : Natural; To : Natural) is
   begin
      Values(To) := Values(From);
   end Move_Int;
   
   function Lt_Int(Left, Right : Natural) return Boolean is
   begin
      return Values(Left) < Values (Right);
   end Lt_Int;
  
   
   package Heap_Sort is new Gnat.Heap_Sort_G(Move_Int, Lt_Int);

begin
   Heap_Sort.Sort(8);
end Integer_Sort;

requires an Ada05 compiler, e.g GNAT GPL 2007
with Ada.Containers.Generic_Array_Sort;
 
procedure Integer_Sort is
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Sort is new Ada.Containers.Generic_Array_Sort
     (Index_Type   => Natural,
      Element_Type => Integer,
      Array_Type   => Int_Array);

begin
   Sort(Values);
end Integer_Sort;
Task: Sort an integer array

C: #include <stdlib.h>  
#include <stdio.h>   

int intcmp(const void *aa, const void *bb)
{
    const int *a = aa, *b = bb;
    return (*a < *b) ? -1 : (*a > *b);
}

int main()
{
    int nums[5] = {2,4,3,1,2};
    qsort(nums, 5, sizeof(int), intcmp);
    printf("result: %d %d %d %d %d\n",
      nums[0], nums[1], nums[2], nums[3], nums[4]);
    return 0;
}











Ada: with Gnat.Heap_Sort_G;
 
procedure Integer_Sort is
   
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Move_Int(From : Natural; To : Natural) is
   begin
      Values(To) := Values(From);
   end Move_Int;
   
   function Lt_Int(Left, Right : Natural) return Boolean is
   begin
      return Values(Left) < Values (Right);
   end Lt_Int;
  
   
   package Heap_Sort is new Gnat.Heap_Sort_G(Move_Int, Lt_Int);

begin
   Heap_Sort.Sort(8);
end Integer_Sort;

requires an Ada05 compiler, e.g GNAT GPL 2007
with Ada.Containers.Generic_Array_Sort;
 
procedure Integer_Sort is
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Sort is new Ada.Containers.Generic_Array_Sort
     (Index_Type   => Natural,
      Element_Type => Integer,
      Array_Type   => Int_Array);

begin
   Sort(Values);
end Integer_Sort;
Task: Sort an integer array


C++: #include <algorithm>

int main()
{
    int nums[] = {2,4,3,1,2};
    std::sort(nums, nums+sizeof(nums)/sizeof(int));
    return 0;
}










Ada: with Gnat.Heap_Sort_G;
 
procedure Integer_Sort is
   
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Move_Int(From : Natural; To : Natural) is
   begin
      Values(To) := Values(From);
   end Move_Int;
   
   function Lt_Int(Left, Right : Natural) return Boolean is
   begin
      return Values(Left) < Values (Right);
   end Lt_Int;
  
   
   package Heap_Sort is new Gnat.Heap_Sort_G(Move_Int, Lt_Int);

begin
   Heap_Sort.Sort(8);
end Integer_Sort;

requires an Ada05 compiler, e.g GNAT GPL 2007
with Ada.Containers.Generic_Array_Sort;
 
procedure Integer_Sort is
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Sort is new Ada.Containers.Generic_Array_Sort
     (Index_Type   => Natural,
      Element_Type => Integer,
      Array_Type   => Int_Array);

begin
   Sort(Values);
end Integer_Sort;
Task: Sort an integer array




Go: package main
import "fmt"
import "sort"

func main() {
  nums := []int {2, 4, 3, 1, 2}
  sort.Ints(nums)
  fmt.Println(nums)
}








Ada: with Gnat.Heap_Sort_G;
 
procedure Integer_Sort is
   
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Move_Int(From : Natural; To : Natural) is
   begin
      Values(To) := Values(From);
   end Move_Int;
   
   function Lt_Int(Left, Right : Natural) return Boolean is
   begin
      return Values(Left) < Values (Right);
   end Lt_Int;
  
   
   package Heap_Sort is new Gnat.Heap_Sort_G(Move_Int, Lt_Int);

begin
   Heap_Sort.Sort(8);
end Integer_Sort;

requires an Ada05 compiler, e.g GNAT GPL 2007
with Ada.Containers.Generic_Array_Sort;
 
procedure Integer_Sort is
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Sort is new Ada.Containers.Generic_Array_Sort
     (Index_Type   => Natural,
      Element_Type => Integer,
      Array_Type   => Int_Array);

begin
   Sort(Values);
end Integer_Sort;
Task: Sort an integer array





Java: import java.util.Arrays;

public class Example {
    public static void main(String[] args)
    {
        int[] nums = {2,4,3,1,2};
        Arrays.sort(nums);
    }
}







Ada: with Gnat.Heap_Sort_G;
 
procedure Integer_Sort is
   
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Move_Int(From : Natural; To : Natural) is
   begin
      Values(To) := Values(From);
   end Move_Int;
   
   function Lt_Int(Left, Right : Natural) return Boolean is
   begin
      return Values(Left) < Values (Right);
   end Lt_Int;
  
   
   package Heap_Sort is new Gnat.Heap_Sort_G(Move_Int, Lt_Int);

begin
   Heap_Sort.Sort(8);
end Integer_Sort;

requires an Ada05 compiler, e.g GNAT GPL 2007
with Ada.Containers.Generic_Array_Sort;
 
procedure Integer_Sort is
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Sort is new Ada.Containers.Generic_Array_Sort
     (Index_Type   => Natural,
      Element_Type => Integer,
      Array_Type   => Int_Array);

begin
   Sort(Values);
end Integer_Sort;
Task: Sort an integer array







Python: nums = [2,4,3,1,2]
nums.sort()





Ada: with Gnat.Heap_Sort_G;
 
procedure Integer_Sort is
   
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Move_Int(From : Natural; To : Natural) is
   begin
      Values(To) := Values(From);
   end Move_Int;
   
   function Lt_Int(Left, Right : Natural) return Boolean is
   begin
      return Values(Left) < Values (Right);
   end Lt_Int;
  
   
   package Heap_Sort is new Gnat.Heap_Sort_G(Move_Int, Lt_Int);

begin
   Heap_Sort.Sort(8);
end Integer_Sort;

requires an Ada05 compiler, e.g GNAT GPL 2007
with Ada.Containers.Generic_Array_Sort;
 
procedure Integer_Sort is
   
   type Int_Array is array(Natural range <>) of Integer;
   Values : Int_Array := (0,1,8,2,7,3,6,4,5);
   
   
   procedure Sort is new Ada.Containers.Generic_Array_Sort
     (Index_Type   => Natural,
      Element_Type => Integer,
      Array_Type   => Int_Array);

begin
   Sort(Values);
end Integer_Sort;
Task: Sort an integer array

C: #include <stdlib.h>  
#include <stdio.h>   

int intcmp(const void *aa, const void *bb)
{
    const int *a = aa, *b = bb;
    return (*a < *b) ? -1 : (*a > *b);
}

int main()
{
    int nums[5] = {2,4,3,1,2};
    qsort(nums, 5, sizeof(int), intcmp);
    printf("result: %d %d %d %d %d\n",
      nums[0], nums[1], nums[2], nums[3], nums[4]);
    return 0;
}
Task: Sort an integer array



C#: using System;
using System.Collections.Generic;

public class Program {
    static void Main() {
        int[] unsorted = { 6, 2, 7, 8, 3, 1, 10, 5, 4, 9 };
        Array.Sort(unsorted);
    }
}
Task: Sort an integer array


C++: #include <algorithm>

int main()
{
    int nums[] = {2,4,3,1,2};
    std::sort(nums, nums+sizeof(nums)/sizeof(int));
    return 0;
}
Task: Sort an integer array





Java: import java.util.Arrays;

public class Example {
    public static void main(String[] args)
    {
        int[] nums = {2,4,3,1,2};
        Arrays.sort(nums);
    }
}
Task: Sort an integer array







Python: nums = [2,4,3,1,2]
nums.sort()
Task: Sort an integer array




Go: package main
import "fmt"
import "sort"

func main() {
  nums := []int {2, 4, 3, 1, 2}
  sort.Ints(nums)
  fmt.Println(nums)
}
Task: Sort an integer array



C#: using System;
using System.Collections.Generic;

public class Program {
    static void Main() {
        int[] unsorted = { 6, 2, 7, 8, 3, 1, 10, 5, 4, 9 };
        Array.Sort(unsorted);
    }
}








Fortran: CALL ISORT@(b, a, n)
Task: Sort an integer array


C++: #include <algorithm>

int main()
{
    int nums[] = {2,4,3,1,2};
    std::sort(nums, nums+sizeof(nums)/sizeof(int));
    return 0;
}









Fortran: CALL ISORT@(b, a, n)
Task: Sort an integer array

C: #include <stdlib.h>  
#include <stdio.h>   

int intcmp(const void *aa, const void *bb)
{
    const int *a = aa, *b = bb;
    return (*a < *b) ? -1 : (*a > *b);
}

int main()
{
    int nums[5] = {2,4,3,1,2};
    qsort(nums, 5, sizeof(int), intcmp);
    printf("result: %d %d %d %d %d\n",
      nums[0], nums[1], nums[2], nums[3], nums[4]);
    return 0;
}










Fortran: CALL ISORT@(b, a, n)
Task: Sort an integer array




Go: package main
import "fmt"
import "sort"

func main() {
  nums := []int {2, 4, 3, 1, 2}
  sort.Ints(nums)
  fmt.Println(nums)
}







Fortran: CALL ISORT@(b, a, n)
Task: Sort an integer array





Java: import java.util.Arrays;

public class Example {
    public static void main(String[] args)
    {
        int[] nums = {2,4,3,1,2};
        Arrays.sort(nums);
    }
}






Fortran: CALL ISORT@(b, a, n)
Task: Sort an integer array






PHP: <?php
$nums = array(2,4,3,1,2);
sort($nums);
?>





Fortran: CALL ISORT@(b, a, n)
Task: Sort an integer array

C: #include <stdlib.h>  
#include <stdio.h>   

int intcmp(const void *aa, const void *bb)
{
    const int *a = aa, *b = bb;
    return (*a < *b) ? -1 : (*a > *b);
}

int main()
{
    int nums[5] = {2,4,3,1,2};
    qsort(nums, 5, sizeof(int), intcmp);
    printf("result: %d %d %d %d %d\n",
      nums[0], nums[1], nums[2], nums[3], nums[4]);
    return 0;
}









COBOL:        PROGRAM-ID. sort-ints.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  array-area             VALUE "54321".
           03  array              PIC 9 OCCURS 5 TIMES.
       01  i                      PIC 9.
       
       PROCEDURE DIVISION.
       main-line.
           PERFORM display-array
           SORT array ASCENDING array
           PERFORM display-array
       
           GOBACK
           .
       display-array.
           PERFORM VARYING i FROM 1 BY 1 UNTIL 5 < i
               DISPLAY array (i) " " NO ADVANCING
           END-PERFORM
           DISPLAY SPACE
           .
Task: Sort an integer array



C#: using System;
using System.Collections.Generic;

public class Program {
    static void Main() {
        int[] unsorted = { 6, 2, 7, 8, 3, 1, 10, 5, 4, 9 };
        Array.Sort(unsorted);
    }
}







COBOL:        PROGRAM-ID. sort-ints.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  array-area             VALUE "54321".
           03  array              PIC 9 OCCURS 5 TIMES.
       01  i                      PIC 9.
       
       PROCEDURE DIVISION.
       main-line.
           PERFORM display-array
           SORT array ASCENDING array
           PERFORM display-array
       
           GOBACK
           .
       display-array.
           PERFORM VARYING i FROM 1 BY 1 UNTIL 5 < i
               DISPLAY array (i) " " NO ADVANCING
           END-PERFORM
           DISPLAY SPACE
           .
Task: Sort an integer array


C++: #include <algorithm>

int main()
{
    int nums[] = {2,4,3,1,2};
    std::sort(nums, nums+sizeof(nums)/sizeof(int));
    return 0;
}








COBOL:        PROGRAM-ID. sort-ints.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  array-area             VALUE "54321".
           03  array              PIC 9 OCCURS 5 TIMES.
       01  i                      PIC 9.
       
       PROCEDURE DIVISION.
       main-line.
           PERFORM display-array
           SORT array ASCENDING array
           PERFORM display-array
       
           GOBACK
           .
       display-array.
           PERFORM VARYING i FROM 1 BY 1 UNTIL 5 < i
               DISPLAY array (i) " " NO ADVANCING
           END-PERFORM
           DISPLAY SPACE
           .
Task: Sort an integer array





Java: import java.util.Arrays;

public class Example {
    public static void main(String[] args)
    {
        int[] nums = {2,4,3,1,2};
        Arrays.sort(nums);
    }
}





COBOL:        PROGRAM-ID. sort-ints.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  array-area             VALUE "54321".
           03  array              PIC 9 OCCURS 5 TIMES.
       01  i                      PIC 9.
       
       PROCEDURE DIVISION.
       main-line.
           PERFORM display-array
           SORT array ASCENDING array
           PERFORM display-array
       
           GOBACK
           .
       display-array.
           PERFORM VARYING i FROM 1 BY 1 UNTIL 5 < i
               DISPLAY array (i) " " NO ADVANCING
           END-PERFORM
           DISPLAY SPACE
           .