WeixiangYan/CodeTransOcean huggingface dataset:
Task: Equilibrium index



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

class Program
{
    static IEnumerable<int> EquilibriumIndices(IEnumerable<int> sequence)
    {
        var left = 0;
        var right = sequence.Sum();
        var index = 0;
        foreach (var element in sequence)
        {
            right -= element;
            if (left == right)
            {
                yield return index;
            }
            left += element;
            index++;
        }
    }

    static void Main()
    {
        foreach (var index in EquilibriumIndices(new[] { -7, 1, 5, 2, -4, 3, 0 }))
        {
            Console.WriteLine(index);
        }
    }
}









Ada: with Ada.Containers.Vectors;

generic
   type Index_Type is range <>;
   type Element_Type is private;
   Zero : Element_Type;
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
   type Array_Type is private;
   with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
package Equilibrium is
   package Index_Vectors is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Index_Type);

   function Get_Indices (From : Array_Type) return Index_Vectors.Vector;

end Equilibrium;
Task: Equilibrium index

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

int list[] = {-7, 1, 5, 2, -4, 3, 0};

int eq_idx(int *a, int len, int **ret)
{
	int i, sum, s, cnt;
	
        cnt = s = sum = 0;
	*ret = malloc(sizeof(int) * len);

	for (i = 0; i < len; i++)
                sum += a[i];

	for (i = 0; i < len; i++) {
		if (s * 2 + a[i] == sum) {
			(*ret)[cnt] = i;
                        cnt++;
                }
		s += a[i];
	}

        
	*ret = realloc(*ret, cnt * sizeof(int));

	return cnt;
}

int main()
{
	int i, cnt, *idx;
	cnt = eq_idx(list, sizeof(list) / sizeof(int), &idx);

	printf("Found:");
	for (i = 0; i < cnt; i++)
                printf(" %d", idx[i]);
	printf("\n");

	return 0;
}











Ada: with Ada.Containers.Vectors;

generic
   type Index_Type is range <>;
   type Element_Type is private;
   Zero : Element_Type;
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
   type Array_Type is private;
   with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
package Equilibrium is
   package Index_Vectors is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Index_Type);

   function Get_Indices (From : Array_Type) return Index_Vectors.Vector;

end Equilibrium;
Task: Equilibrium index


C++: #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

template <typename T>
std::vector<size_t> equilibrium(T first, T last)
{
    typedef typename std::iterator_traits<T>::value_type value_t;

    value_t left  = 0;
    value_t right = std::accumulate(first, last, value_t(0));
    std::vector<size_t> result;

    for (size_t index = 0; first != last; ++first, ++index)
    {
        right -= *first;
        if (left == right)
        {
            result.push_back(index);
        }
        left += *first;
    }
    return result;
}

template <typename T>
void print(const T& value)
{
    std::cout << value << "\n";
}

int main() 
{
    const int data[] = { -7, 1, 5, 2, -4, 3, 0 };

    std::vector<size_t> indices(equilibrium(data, data + 7));

    std::for_each(indices.begin(), indices.end(), print<size_t>);
}










Ada: with Ada.Containers.Vectors;

generic
   type Index_Type is range <>;
   type Element_Type is private;
   Zero : Element_Type;
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
   type Array_Type is private;
   with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
package Equilibrium is
   package Index_Vectors is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Index_Type);

   function Get_Indices (From : Array_Type) return Index_Vectors.Vector;

end Equilibrium;
Task: Equilibrium index




Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

func main() {
    fmt.Println(ex([]int32{-7, 1, 5, 2, -4, 3, 0}))

    
    
    
    rand.Seed(time.Now().UnixNano())
    verylong := make([]int32, 1e6)
    for i := range verylong {
        verylong[i] = rand.Int31n(1001) - 500
    }
    fmt.Println(ex(verylong))
}

func ex(s []int32) (eq []int) {
    var r, l int64
    for _, el := range s {
        r += int64(el)
    }
    for i, el := range s {
        r -= int64(el)
        if l == r {
            eq = append(eq, i)
        }
        l += int64(el)
    }
    return
}








Ada: with Ada.Containers.Vectors;

generic
   type Index_Type is range <>;
   type Element_Type is private;
   Zero : Element_Type;
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
   type Array_Type is private;
   with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
package Equilibrium is
   package Index_Vectors is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Index_Type);

   function Get_Indices (From : Array_Type) return Index_Vectors.Vector;

end Equilibrium;
Task: Equilibrium index





Java: public class Equlibrium {
	public static void main(String[] args) {
		int[] sequence = {-7, 1, 5, 2, -4, 3, 0};
		equlibrium_indices(sequence);
	}

	public static void equlibrium_indices(int[] sequence){
		
		int totalSum = 0;
		for (int n : sequence) {
			totalSum += n;
		}
		
		int runningSum = 0;
		for (int i = 0; i < sequence.length; i++) {
			int n = sequence[i];
			if (totalSum - runningSum - n == runningSum) {
				System.out.println(i);
			}
			runningSum += n;
		}
	}
}







Ada: with Ada.Containers.Vectors;

generic
   type Index_Type is range <>;
   type Element_Type is private;
   Zero : Element_Type;
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
   type Array_Type is private;
   with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
package Equilibrium is
   package Index_Vectors is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Index_Type);

   function Get_Indices (From : Array_Type) return Index_Vectors.Vector;

end Equilibrium;
Task: Equilibrium index







Python: def eqindex2Pass(data):
    "Two pass"
    suml, sumr, ddelayed = 0, sum(data), 0
    for i, d in enumerate(data):
        suml += ddelayed
        sumr -= d
        ddelayed = d
        if suml == sumr:
            yield i





Ada: with Ada.Containers.Vectors;

generic
   type Index_Type is range <>;
   type Element_Type is private;
   Zero : Element_Type;
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
   type Array_Type is private;
   with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
package Equilibrium is
   package Index_Vectors is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Index_Type);

   function Get_Indices (From : Array_Type) return Index_Vectors.Vector;

end Equilibrium;
Task: Equilibrium index








VB: arr = Array(-7,1,5,2,-4,3,0)
WScript.StdOut.Write equilibrium(arr,UBound(arr))
WScript.StdOut.WriteLine

Function equilibrium(arr,n)
	sum = 0
	leftsum = 0
	
	For i = 0 To UBound(arr)
		sum = sum + arr(i)
	Next
	For i = 0 To UBound(arr)
		sum = sum - arr(i)
		If leftsum = sum Then
			equilibrium = equilibrium & i & ", "
		End If
		leftsum = leftsum + arr(i)
	Next
End Function




Ada: with Ada.Containers.Vectors;

generic
   type Index_Type is range <>;
   type Element_Type is private;
   Zero : Element_Type;
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
   type Array_Type is private;
   with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
package Equilibrium is
   package Index_Vectors is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Index_Type);

   function Get_Indices (From : Array_Type) return Index_Vectors.Vector;

end Equilibrium;
Task: Equilibrium index

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

int list[] = {-7, 1, 5, 2, -4, 3, 0};

int eq_idx(int *a, int len, int **ret)
{
	int i, sum, s, cnt;
	
        cnt = s = sum = 0;
	*ret = malloc(sizeof(int) * len);

	for (i = 0; i < len; i++)
                sum += a[i];

	for (i = 0; i < len; i++) {
		if (s * 2 + a[i] == sum) {
			(*ret)[cnt] = i;
                        cnt++;
                }
		s += a[i];
	}

        
	*ret = realloc(*ret, cnt * sizeof(int));

	return cnt;
}

int main()
{
	int i, cnt, *idx;
	cnt = eq_idx(list, sizeof(list) / sizeof(int), &idx);

	printf("Found:");
	for (i = 0; i < cnt; i++)
                printf(" %d", idx[i]);
	printf("\n");

	return 0;
}
Task: Equilibrium index



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

class Program
{
    static IEnumerable<int> EquilibriumIndices(IEnumerable<int> sequence)
    {
        var left = 0;
        var right = sequence.Sum();
        var index = 0;
        foreach (var element in sequence)
        {
            right -= element;
            if (left == right)
            {
                yield return index;
            }
            left += element;
            index++;
        }
    }

    static void Main()
    {
        foreach (var index in EquilibriumIndices(new[] { -7, 1, 5, 2, -4, 3, 0 }))
        {
            Console.WriteLine(index);
        }
    }
}
Task: Equilibrium index


C++: #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

template <typename T>
std::vector<size_t> equilibrium(T first, T last)
{
    typedef typename std::iterator_traits<T>::value_type value_t;

    value_t left  = 0;
    value_t right = std::accumulate(first, last, value_t(0));
    std::vector<size_t> result;

    for (size_t index = 0; first != last; ++first, ++index)
    {
        right -= *first;
        if (left == right)
        {
            result.push_back(index);
        }
        left += *first;
    }
    return result;
}

template <typename T>
void print(const T& value)
{
    std::cout << value << "\n";
}

int main() 
{
    const int data[] = { -7, 1, 5, 2, -4, 3, 0 };

    std::vector<size_t> indices(equilibrium(data, data + 7));

    std::for_each(indices.begin(), indices.end(), print<size_t>);
}
Task: Equilibrium index





Java: public class Equlibrium {
	public static void main(String[] args) {
		int[] sequence = {-7, 1, 5, 2, -4, 3, 0};
		equlibrium_indices(sequence);
	}

	public static void equlibrium_indices(int[] sequence){
		
		int totalSum = 0;
		for (int n : sequence) {
			totalSum += n;
		}
		
		int runningSum = 0;
		for (int i = 0; i < sequence.length; i++) {
			int n = sequence[i];
			if (totalSum - runningSum - n == runningSum) {
				System.out.println(i);
			}
			runningSum += n;
		}
	}
}
Task: Equilibrium index







Python: def eqindex2Pass(data):
    "Two pass"
    suml, sumr, ddelayed = 0, sum(data), 0
    for i, d in enumerate(data):
        suml += ddelayed
        sumr -= d
        ddelayed = d
        if suml == sumr:
            yield i
Task: Equilibrium index








VB: arr = Array(-7,1,5,2,-4,3,0)
WScript.StdOut.Write equilibrium(arr,UBound(arr))
WScript.StdOut.WriteLine

Function equilibrium(arr,n)
	sum = 0
	leftsum = 0
	
	For i = 0 To UBound(arr)
		sum = sum + arr(i)
	Next
	For i = 0 To UBound(arr)
		sum = sum - arr(i)
		If leftsum = sum Then
			equilibrium = equilibrium & i & ", "
		End If
		leftsum = leftsum + arr(i)
	Next
End Function
Task: Equilibrium index




Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

func main() {
    fmt.Println(ex([]int32{-7, 1, 5, 2, -4, 3, 0}))

    
    
    
    rand.Seed(time.Now().UnixNano())
    verylong := make([]int32, 1e6)
    for i := range verylong {
        verylong[i] = rand.Int31n(1001) - 500
    }
    fmt.Println(ex(verylong))
}

func ex(s []int32) (eq []int) {
    var r, l int64
    for _, el := range s {
        r += int64(el)
    }
    for i, el := range s {
        r -= int64(el)
        if l == r {
            eq = append(eq, i)
        }
        l += int64(el)
    }
    return
}
Task: Equilibrium index



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

class Program
{
    static IEnumerable<int> EquilibriumIndices(IEnumerable<int> sequence)
    {
        var left = 0;
        var right = sequence.Sum();
        var index = 0;
        foreach (var element in sequence)
        {
            right -= element;
            if (left == right)
            {
                yield return index;
            }
            left += element;
            index++;
        }
    }

    static void Main()
    {
        foreach (var index in EquilibriumIndices(new[] { -7, 1, 5, 2, -4, 3, 0 }))
        {
            Console.WriteLine(index);
        }
    }
}








Fortran: program Equilibrium
  implicit none
  
  integer :: array(7) = (/ -7, 1, 5, 2, -4, 3, 0 /)
 
  call equil_index(array)
 
contains

subroutine equil_index(a)
  integer, intent(in) :: a(:)
  integer :: i

  do i = 1, size(a)
    if(sum(a(1:i-1)) == sum(a(i+1:size(a)))) write(*,*) i
  end do

end subroutine
end program
Task: Equilibrium index


C++: #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

template <typename T>
std::vector<size_t> equilibrium(T first, T last)
{
    typedef typename std::iterator_traits<T>::value_type value_t;

    value_t left  = 0;
    value_t right = std::accumulate(first, last, value_t(0));
    std::vector<size_t> result;

    for (size_t index = 0; first != last; ++first, ++index)
    {
        right -= *first;
        if (left == right)
        {
            result.push_back(index);
        }
        left += *first;
    }
    return result;
}

template <typename T>
void print(const T& value)
{
    std::cout << value << "\n";
}

int main() 
{
    const int data[] = { -7, 1, 5, 2, -4, 3, 0 };

    std::vector<size_t> indices(equilibrium(data, data + 7));

    std::for_each(indices.begin(), indices.end(), print<size_t>);
}









Fortran: program Equilibrium
  implicit none
  
  integer :: array(7) = (/ -7, 1, 5, 2, -4, 3, 0 /)
 
  call equil_index(array)
 
contains

subroutine equil_index(a)
  integer, intent(in) :: a(:)
  integer :: i

  do i = 1, size(a)
    if(sum(a(1:i-1)) == sum(a(i+1:size(a)))) write(*,*) i
  end do

end subroutine
end program
Task: Equilibrium index

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

int list[] = {-7, 1, 5, 2, -4, 3, 0};

int eq_idx(int *a, int len, int **ret)
{
	int i, sum, s, cnt;
	
        cnt = s = sum = 0;
	*ret = malloc(sizeof(int) * len);

	for (i = 0; i < len; i++)
                sum += a[i];

	for (i = 0; i < len; i++) {
		if (s * 2 + a[i] == sum) {
			(*ret)[cnt] = i;
                        cnt++;
                }
		s += a[i];
	}

        
	*ret = realloc(*ret, cnt * sizeof(int));

	return cnt;
}

int main()
{
	int i, cnt, *idx;
	cnt = eq_idx(list, sizeof(list) / sizeof(int), &idx);

	printf("Found:");
	for (i = 0; i < cnt; i++)
                printf(" %d", idx[i]);
	printf("\n");

	return 0;
}










Fortran: program Equilibrium
  implicit none
  
  integer :: array(7) = (/ -7, 1, 5, 2, -4, 3, 0 /)
 
  call equil_index(array)
 
contains

subroutine equil_index(a)
  integer, intent(in) :: a(:)
  integer :: i

  do i = 1, size(a)
    if(sum(a(1:i-1)) == sum(a(i+1:size(a)))) write(*,*) i
  end do

end subroutine
end program
Task: Equilibrium index





Java: public class Equlibrium {
	public static void main(String[] args) {
		int[] sequence = {-7, 1, 5, 2, -4, 3, 0};
		equlibrium_indices(sequence);
	}

	public static void equlibrium_indices(int[] sequence){
		
		int totalSum = 0;
		for (int n : sequence) {
			totalSum += n;
		}
		
		int runningSum = 0;
		for (int i = 0; i < sequence.length; i++) {
			int n = sequence[i];
			if (totalSum - runningSum - n == runningSum) {
				System.out.println(i);
			}
			runningSum += n;
		}
	}
}






Fortran: program Equilibrium
  implicit none
  
  integer :: array(7) = (/ -7, 1, 5, 2, -4, 3, 0 /)
 
  call equil_index(array)
 
contains

subroutine equil_index(a)
  integer, intent(in) :: a(:)
  integer :: i

  do i = 1, size(a)
    if(sum(a(1:i-1)) == sum(a(i+1:size(a)))) write(*,*) i
  end do

end subroutine
end program
Task: Equilibrium index







Python: def eqindex2Pass(data):
    "Two pass"
    suml, sumr, ddelayed = 0, sum(data), 0
    for i, d in enumerate(data):
        suml += ddelayed
        sumr -= d
        ddelayed = d
        if suml == sumr:
            yield i




Fortran: program Equilibrium
  implicit none
  
  integer :: array(7) = (/ -7, 1, 5, 2, -4, 3, 0 /)
 
  call equil_index(array)
 
contains

subroutine equil_index(a)
  integer, intent(in) :: a(:)
  integer :: i

  do i = 1, size(a)
    if(sum(a(1:i-1)) == sum(a(i+1:size(a)))) write(*,*) i
  end do

end subroutine
end program
Task: Equilibrium index








VB: arr = Array(-7,1,5,2,-4,3,0)
WScript.StdOut.Write equilibrium(arr,UBound(arr))
WScript.StdOut.WriteLine

Function equilibrium(arr,n)
	sum = 0
	leftsum = 0
	
	For i = 0 To UBound(arr)
		sum = sum + arr(i)
	Next
	For i = 0 To UBound(arr)
		sum = sum - arr(i)
		If leftsum = sum Then
			equilibrium = equilibrium & i & ", "
		End If
		leftsum = leftsum + arr(i)
	Next
End Function



Fortran: program Equilibrium
  implicit none
  
  integer :: array(7) = (/ -7, 1, 5, 2, -4, 3, 0 /)
 
  call equil_index(array)
 
contains

subroutine equil_index(a)
  integer, intent(in) :: a(:)
  integer :: i

  do i = 1, size(a)
    if(sum(a(1:i-1)) == sum(a(i+1:size(a)))) write(*,*) i
  end do

end subroutine
end program
Task: Equilibrium index






PHP: <?php
$arr = array(-7, 1, 5, 2, -4, 3, 0);

function getEquilibriums($arr) {
    $right = array_sum($arr);
    $left = 0;
    $equilibriums = array();
    foreach($arr as $key => $value){
        $right -= $value;
        if($left == $right) $equilibriums[] = $key;
        $left += $value;
    }
    return $equilibriums;
}

echo "# results:\n";
foreach (getEquilibriums($arr) as $r) echo "$r, ";
?>





Fortran: program Equilibrium
  implicit none
  
  integer :: array(7) = (/ -7, 1, 5, 2, -4, 3, 0 /)
 
  call equil_index(array)
 
contains

subroutine equil_index(a)
  integer, intent(in) :: a(:)
  integer :: i

  do i = 1, size(a)
    if(sum(a(1:i-1)) == sum(a(i+1:size(a)))) write(*,*) i
  end do

end subroutine
end program
Task: Equilibrium index






PHP: <?php
$arr = array(-7, 1, 5, 2, -4, 3, 0);

function getEquilibriums($arr) {
    $right = array_sum($arr);
    $left = 0;
    $equilibriums = array();
    foreach($arr as $key => $value){
        $right -= $value;
        if($left == $right) $equilibriums[] = $key;
        $left += $value;
    }
    return $equilibriums;
}

echo "# results:\n";
foreach (getEquilibriums($arr) as $r) echo "$r, ";
?>
Task: Equilibrium index






PHP: <?php
$arr = array(-7, 1, 5, 2, -4, 3, 0);

function getEquilibriums($arr) {
    $right = array_sum($arr);
    $left = 0;
    $equilibriums = array();
    foreach($arr as $key => $value){
        $right -= $value;
        if($left == $right) $equilibriums[] = $key;
        $left += $value;
    }
    return $equilibriums;
}

echo "# results:\n";
foreach (getEquilibriums($arr) as $r) echo "$r, ";
?>






Ada: with Ada.Containers.Vectors;

generic
   type Index_Type is range <>;
   type Element_Type is private;
   Zero : Element_Type;
   with function "+" (Left, Right : Element_Type) return Element_Type is <>;
   with function "-" (Left, Right : Element_Type) return Element_Type is <>;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
   type Array_Type is private;
   with function Element (From : Array_Type; Key : Index_Type) return Element_Type is <>;
package Equilibrium is
   package Index_Vectors is new Ada.Containers.Vectors
      (Index_Type => Positive, Element_Type => Index_Type);

   function Get_Indices (From : Array_Type) return Index_Vectors.Vector;

end Equilibrium;
Task: Matrix transposition



C#: using System;
using System.Text;

namespace prog
{
	class MainClass
	{						
		public static void Main (string[] args)
		{
			double[,] m = { {1,2,3},{4,5,6},{7,8,9} };
			
			double[,] t = Transpose( m );	
			
			for( int i=0; i<t.GetLength(0); i++ )
			{
				for( int j=0; j<t.GetLength(1); j++ )		
					Console.Write( t[i,j] + "  " );
				Console.WriteLine("");
			}
		}
		
		public static double[,] Transpose( double[,] m )
		{
			double[,] t = new double[m.GetLength(1),m.GetLength(0)];
			for( int i=0; i<m.GetLength(0); i++ )
				for( int j=0; j<m.GetLength(1); j++ )
					t[j,i] = m[i,j];			
			
			return t;
		}
	}
}









Ada: with Ada.Numerics.Real_Arrays;  use Ada.Numerics.Real_Arrays;
with Ada.Text_IO;               use Ada.Text_IO; 
 
procedure Matrix_Transpose is
   procedure Put (X : Real_Matrix) is
      type Fixed is delta 0.01 range -500.0..500.0;
   begin
      for I in X'Range (1) loop
         for J in X'Range (2) loop
            Put (Fixed'Image (Fixed (X (I, J))));
         end loop;
         New_Line;
      end loop;
   end Put;
    
   Matrix : constant Real_Matrix :=
            (  (0.0, 0.1, 0.2, 0.3),
               (0.4, 0.5, 0.6, 0.7),
               (0.8, 0.9, 1.0, 1.1)
            );
begin
   Put_Line ("Before Transposition:");
   Put (Matrix);
   New_Line;
   Put_Line ("After Transposition:");
   Put (Transpose (Matrix));
end Matrix_Transpose;
Task: Matrix transposition

C: #include <stdio.h>

void transpose(void *dest, void *src, int src_h, int src_w)
{
	int i, j;
	double (*d)[src_h] = dest, (*s)[src_w] = src;
	for (i = 0; i < src_h; i++)
		for (j = 0; j < src_w; j++)
			d[j][i] = s[i][j];
}

int main()
{
	int i, j;
	double a[3][5] = {{ 0, 1, 2, 3, 4 },
			  { 5, 6, 7, 8, 9 },
			  { 1, 0, 0, 0, 42}};
	double b[5][3];
	transpose(b, a, 3, 5);

	for (i = 0; i < 5; i++)
		for (j = 0; j < 3; j++)
			printf("%g%c", b[i][j], j == 2 ? '\n' : ' ');
	return 0;
}











Ada: with Ada.Numerics.Real_Arrays;  use Ada.Numerics.Real_Arrays;
with Ada.Text_IO;               use Ada.Text_IO; 
 
procedure Matrix_Transpose is
   procedure Put (X : Real_Matrix) is
      type Fixed is delta 0.01 range -500.0..500.0;
   begin
      for I in X'Range (1) loop
         for J in X'Range (2) loop
            Put (Fixed'Image (Fixed (X (I, J))));
         end loop;
         New_Line;
      end loop;
   end Put;
    
   Matrix : constant Real_Matrix :=
            (  (0.0, 0.1, 0.2, 0.3),
               (0.4, 0.5, 0.6, 0.7),
               (0.8, 0.9, 1.0, 1.1)
            );
begin
   Put_Line ("Before Transposition:");
   Put (Matrix);
   New_Line;
   Put_Line ("After Transposition:");
   Put (Transpose (Matrix));
end Matrix_Transpose;