WeixiangYan/CodeTransOcean huggingface dataset:
Task: Runge-Kutta method

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

double rk4(double(*f)(double, double), double dx, double x, double y)
{
	double	k1 = dx * f(x, y),
		k2 = dx * f(x + dx / 2, y + k1 / 2),
		k3 = dx * f(x + dx / 2, y + k2 / 2),
		k4 = dx * f(x + dx, y + k3);
	return y + (k1 + 2 * k2 + 2 * k3 + k4) / 6;
}

double rate(double x, double y)
{
	return x * sqrt(y);
}

int main(void)
{
	double *y, x, y2;
	double x0 = 0, x1 = 10, dx = .1;
	int i, n = 1 + (x1 - x0)/dx;
	y = (double *)malloc(sizeof(double) * n);

	for (y[0] = 1, i = 1; i < n; i++)
		y[i] = rk4(rate, dx, x0 + dx * (i - 1), y[i-1]);

	printf("x\ty\trel. err.\n------------\n");
	for (i = 0; i < n; i += 10) {
		x = x0 + dx * i;
		y2 = pow(x * x / 4 + 1, 2);
		printf("%g\t%g\t%g\n", x, y[i], y[i]/y2 - 1);
	}

	return 0;
}










Fortran: program rungekutta
    implicit none
    integer, parameter :: dp = kind(1d0)
    real(dp) :: t, dt, tstart, tstop
    real(dp) :: y, k1, k2, k3, k4
    
    tstart = 0.0d0
    tstop = 10.0d0
    dt = 0.1d0
    y = 1.0d0
    t = tstart
    write (6, '(a,f4.1,a,f12.8,a,es13.6)') 'y(', t, ') = ', y, ' error = ', &
        abs(y-(t**2+4)**2/16)
    do while (t < tstop)
        k1 = dt*f(t, y)
        k2 = dt*f(t+dt/2, y+k1/2)
        k3 = dt*f(t+dt/2, y+k2/2)
        k4 = dt*f(t+dt, y+k3)
        y = y+(k1+2*(k2+k3)+k4)/6
        t = t+dt
        if (abs(nint(t)-t) <= 1d-12) then
            write (6, '(a,f4.1,a,f12.8,a,es13.6)') 'y(', t, ') = ', y, ' error = ', &
                abs(y-(t**2+4)**2/16)
        end if
    end do
contains
    function f(t,y)
        real(dp), intent(in) :: t, y
        real(dp) :: f

        f = t*sqrt(y)
    end function f
end program rungekutta
Task: Runge-Kutta method




Go: package main

import (
    "fmt"
    "math"
)

type ypFunc func(t, y float64) float64
type ypStepFunc func(t, y, dt float64) float64




func newRK4Step(yp ypFunc) ypStepFunc {
    return func(t, y, dt float64) float64 {
        dy1 := dt * yp(t, y)
        dy2 := dt * yp(t+dt/2, y+dy1/2)
        dy3 := dt * yp(t+dt/2, y+dy2/2)
        dy4 := dt * yp(t+dt, y+dy3)
        return y + (dy1+2*(dy2+dy3)+dy4)/6
    }
}


func yprime(t, y float64) float64 {
    return t * math.Sqrt(y)
}


func actual(t float64) float64 {
    t = t*t + 4
    return t * t / 16
}

func main() {
    t0, tFinal := 0, 10 
    dtPrint := 1        
    y0 := 1.            
    dtStep := .1        

    t, y := float64(t0), y0
    ypStep := newRK4Step(yprime)
    for t1 := t0 + dtPrint; t1 <= tFinal; t1 += dtPrint {
        printErr(t, y) 
        for steps := int(float64(dtPrint)/dtStep + .5); steps > 1; steps-- {
            y = ypStep(t, y, dtStep)
            t += dtStep
        }
        y = ypStep(t, y, float64(t1)-t) 
        t = float64(t1)
    }
    printErr(t, y) 
}

func printErr(t, y float64) {
    fmt.Printf("y(%.1f) = %f Error: %e\n", t, y, math.Abs(actual(t)-y))
}







Fortran: program rungekutta
    implicit none
    integer, parameter :: dp = kind(1d0)
    real(dp) :: t, dt, tstart, tstop
    real(dp) :: y, k1, k2, k3, k4
    
    tstart = 0.0d0
    tstop = 10.0d0
    dt = 0.1d0
    y = 1.0d0
    t = tstart
    write (6, '(a,f4.1,a,f12.8,a,es13.6)') 'y(', t, ') = ', y, ' error = ', &
        abs(y-(t**2+4)**2/16)
    do while (t < tstop)
        k1 = dt*f(t, y)
        k2 = dt*f(t+dt/2, y+k1/2)
        k3 = dt*f(t+dt/2, y+k2/2)
        k4 = dt*f(t+dt, y+k3)
        y = y+(k1+2*(k2+k3)+k4)/6
        t = t+dt
        if (abs(nint(t)-t) <= 1d-12) then
            write (6, '(a,f4.1,a,f12.8,a,es13.6)') 'y(', t, ') = ', y, ' error = ', &
                abs(y-(t**2+4)**2/16)
        end if
    end do
contains
    function f(t,y)
        real(dp), intent(in) :: t, y
        real(dp) :: f

        f = t*sqrt(y)
    end function f
end program rungekutta
Task: Runge-Kutta method





Java: import static java.lang.Math.*;
import java.util.function.BiFunction;

public class RungeKutta {

    static void runge(BiFunction<Double, Double, Double> yp_func, double[] t,
            double[] y, double dt) {

        for (int n = 0; n < t.length - 1; n++) {
            double dy1 = dt * yp_func.apply(t[n], y[n]);
            double dy2 = dt * yp_func.apply(t[n] + dt / 2.0, y[n] + dy1 / 2.0);
            double dy3 = dt * yp_func.apply(t[n] + dt / 2.0, y[n] + dy2 / 2.0);
            double dy4 = dt * yp_func.apply(t[n] + dt, y[n] + dy3);
            t[n + 1] = t[n] + dt;
            y[n + 1] = y[n] + (dy1 + 2.0 * (dy2 + dy3) + dy4) / 6.0;
        }
    }

    static double calc_err(double t, double calc) {
        double actual = pow(pow(t, 2.0) + 4.0, 2) / 16.0;
        return abs(actual - calc);
    }

    public static void main(String[] args) {
        double dt = 0.10;
        double[] t_arr = new double[101];
        double[] y_arr = new double[101];
        y_arr[0] = 1.0;

        runge((t, y) -> t * sqrt(y), t_arr, y_arr, dt);

        for (int i = 0; i < t_arr.length; i++)
            if (i % 10 == 0)
                System.out.printf("y(%.1f) = %.8f Error: %.6f%n",
                        t_arr[i], y_arr[i],
                        calc_err(t_arr[i], y_arr[i]));
    }
}






Fortran: program rungekutta
    implicit none
    integer, parameter :: dp = kind(1d0)
    real(dp) :: t, dt, tstart, tstop
    real(dp) :: y, k1, k2, k3, k4
    
    tstart = 0.0d0
    tstop = 10.0d0
    dt = 0.1d0
    y = 1.0d0
    t = tstart
    write (6, '(a,f4.1,a,f12.8,a,es13.6)') 'y(', t, ') = ', y, ' error = ', &
        abs(y-(t**2+4)**2/16)
    do while (t < tstop)
        k1 = dt*f(t, y)
        k2 = dt*f(t+dt/2, y+k1/2)
        k3 = dt*f(t+dt/2, y+k2/2)
        k4 = dt*f(t+dt, y+k3)
        y = y+(k1+2*(k2+k3)+k4)/6
        t = t+dt
        if (abs(nint(t)-t) <= 1d-12) then
            write (6, '(a,f4.1,a,f12.8,a,es13.6)') 'y(', t, ') = ', y, ' error = ', &
                abs(y-(t**2+4)**2/16)
        end if
    end do
contains
    function f(t,y)
        real(dp), intent(in) :: t, y
        real(dp) :: f

        f = t*sqrt(y)
    end function f
end program rungekutta
Task: Runge-Kutta method







Python: from math import sqrt
 
def rk4(f, x0, y0, x1, n):
    vx = [0] * (n + 1)
    vy = [0] * (n + 1)
    h = (x1 - x0) / float(n)
    vx[0] = x = x0
    vy[0] = y = y0
    for i in range(1, n + 1):
        k1 = h * f(x, y)
        k2 = h * f(x + 0.5 * h, y + 0.5 * k1)
        k3 = h * f(x + 0.5 * h, y + 0.5 * k2)
        k4 = h * f(x + h, y + k3)
        vx[i] = x = x0 + i * h
        vy[i] = y = y + (k1 + k2 + k2 + k3 + k3 + k4) / 6
    return vx, vy
 
def f(x, y):
    return x * sqrt(y)
 
vx, vy = rk4(f, 0, 1, 10, 100)
for x, y in list(zip(vx, vy))[::10]:
    print("%4.1f %10.5f %+12.4e" % (x, y, y - (4 + x * x)**2 / 16))

 0.0    1.00000  +0.0000e+00
 1.0    1.56250  -1.4572e-07
 2.0    4.00000  -9.1948e-07
 3.0   10.56250  -2.9096e-06
 4.0   24.99999  -6.2349e-06
 5.0   52.56249  -1.0820e-05
 6.0   99.99998  -1.6595e-05
 7.0  175.56248  -2.3518e-05
 8.0  288.99997  -3.1565e-05
 9.0  451.56246  -4.0723e-05
10.0  675.99995  -5.0983e-05




Fortran: program rungekutta
    implicit none
    integer, parameter :: dp = kind(1d0)
    real(dp) :: t, dt, tstart, tstop
    real(dp) :: y, k1, k2, k3, k4
    
    tstart = 0.0d0
    tstop = 10.0d0
    dt = 0.1d0
    y = 1.0d0
    t = tstart
    write (6, '(a,f4.1,a,f12.8,a,es13.6)') 'y(', t, ') = ', y, ' error = ', &
        abs(y-(t**2+4)**2/16)
    do while (t < tstop)
        k1 = dt*f(t, y)
        k2 = dt*f(t+dt/2, y+k1/2)
        k3 = dt*f(t+dt/2, y+k2/2)
        k4 = dt*f(t+dt, y+k3)
        y = y+(k1+2*(k2+k3)+k4)/6
        t = t+dt
        if (abs(nint(t)-t) <= 1d-12) then
            write (6, '(a,f4.1,a,f12.8,a,es13.6)') 'y(', t, ') = ', y, ' error = ', &
                abs(y-(t**2+4)**2/16)
        end if
    end do
contains
    function f(t,y)
        real(dp), intent(in) :: t, y
        real(dp) :: f

        f = t*sqrt(y)
    end function f
end program rungekutta
Task: Multiplication tables



C#: using System;

namespace multtbl
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write(" X".PadRight(4));
            for (int i = 1; i <= 12; i++)
                Console.Write(i.ToString("####").PadLeft(4));

            Console.WriteLine();
            Console.Write(" ___");

            for (int i = 1; i <= 12; i++)
                Console.Write(" ___");

            Console.WriteLine();
            for (int row = 1; row <= 12; row++)
            {
                Console.Write(row.ToString("###").PadLeft(3).PadRight(4));
                for (int col = 1; col <= 12; col++)
                {
                    if (row <= col)
                        Console.Write((row * col).ToString("###").PadLeft(4));
                    else
                        Console.Write("".PadLeft(4));
                }

                Console.WriteLine();
            }

            Console.WriteLine();
            Console.ReadLine();
        }
    }
}









Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed;  use Ada.Strings.Fixed;
procedure Multiplication_Table is
   package IO is new Integer_IO (Integer);
   use IO;
begin
   Put ("  | ");
   for Row in 1..12 loop
      Put (Row, Width => 4);
   end loop;
   New_Line;
   Put_Line ("
   for Row in 1..12 loop
      Put (Row, Width => 2);
      Put ("| ");
      for Column in 1..12 loop
         if Column < Row then
            Put ("    ");
         else
            Put (Row * Column, Width => 4);
         end if;
      end loop;
      New_Line;
   end loop;
end Multiplication_Table;
Task: Multiplication tables

C: #include <stdio.h>

int main(void)
{
	int i, j, n = 12;
 
	for (j = 1; j <= n; j++) printf("%3d%c", j, j != n ? ' ' : '\n');
	for (j = 0; j <= n; j++) printf(j != n ? "----" : "+\n");

	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++)
			printf(j < i ? "    " : "%3d ", i * j);
                printf("| %d\n", i);
        }
 
	return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed;  use Ada.Strings.Fixed;
procedure Multiplication_Table is
   package IO is new Integer_IO (Integer);
   use IO;
begin
   Put ("  | ");
   for Row in 1..12 loop
      Put (Row, Width => 4);
   end loop;
   New_Line;
   Put_Line ("
   for Row in 1..12 loop
      Put (Row, Width => 2);
      Put ("| ");
      for Column in 1..12 loop
         if Column < Row then
            Put ("    ");
         else
            Put (Row * Column, Width => 4);
         end if;
      end loop;
      New_Line;
   end loop;
end Multiplication_Table;
Task: Multiplication tables


C++: #include <iostream>
#include <iomanip>
#include <cmath> 
#include <algorithm> 

size_t table_column_width(const int min, const int max)
{
    unsigned int abs_max = std::max(max*max, min*min);

    
    
    
    
    size_t colwidth = 2 + std::log10(abs_max);

    
    
    
    if (min < 0 && max > 0)
	++colwidth;
    return colwidth;
}

struct Writer_
{
    decltype(std::setw(1)) fmt_;
    Writer_(size_t w) : fmt_(std::setw(w)) {}
    template<class T_> Writer_& operator()(const T_& info) { std::cout << fmt_ << info; return *this; }
};

void print_table_header(const int min, const int max)
{
    Writer_ write(table_column_width(min, max));

    
    write(" ");
    for(int col = min; col <= max; ++col)
        write(col);

    
    std::cout << std::endl << std::endl;
}

void print_table_row(const int num, const int min, const int max)
{
    Writer_ write(table_column_width(min, max));

    
    write(num);

    
    for(int multiplicand = min; multiplicand < num; ++multiplicand)
        write(" ");

    
    for(int multiplicand = num; multiplicand <= max; ++multiplicand)
        write(num * multiplicand);

    
    std::cout << std::endl << std::endl;
}

void print_table(const int min, const int max)
{
    
    print_table_header(min, max);

    
    for(int row = min; row <= max; ++row)
        print_table_row(row, min, max);
}

int main()
{
    print_table(1, 12);
    return 0;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed;  use Ada.Strings.Fixed;
procedure Multiplication_Table is
   package IO is new Integer_IO (Integer);
   use IO;
begin
   Put ("  | ");
   for Row in 1..12 loop
      Put (Row, Width => 4);
   end loop;
   New_Line;
   Put_Line ("
   for Row in 1..12 loop
      Put (Row, Width => 2);
      Put ("| ");
      for Column in 1..12 loop
         if Column < Row then
            Put ("    ");
         else
            Put (Row * Column, Width => 4);
         end if;
      end loop;
      New_Line;
   end loop;
end Multiplication_Table;
Task: Multiplication tables




Go: package main

import (
    "fmt"
)

func main() {
    fmt.Print(" x |")
    for i := 1; i <= 12; i++ {
        fmt.Printf("%4d", i)
    }
    fmt.Print("\n---+")
    for i := 1; i <= 12; i++ {
        fmt.Print("----")
    }
    for j := 1; j <= 12; j++ {
        fmt.Printf("\n%2d |", j)
        for i := 1; i <= 12; i++ {
            if i >= j {
                fmt.Printf("%4d", i*j)
            } else {
                fmt.Print("    ")
            }
        }
    }
    fmt.Println("")
}








Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed;  use Ada.Strings.Fixed;
procedure Multiplication_Table is
   package IO is new Integer_IO (Integer);
   use IO;
begin
   Put ("  | ");
   for Row in 1..12 loop
      Put (Row, Width => 4);
   end loop;
   New_Line;
   Put_Line ("
   for Row in 1..12 loop
      Put (Row, Width => 2);
      Put ("| ");
      for Column in 1..12 loop
         if Column < Row then
            Put ("    ");
         else
            Put (Row * Column, Width => 4);
         end if;
      end loop;
      New_Line;
   end loop;
end Multiplication_Table;
Task: Multiplication tables





Java: public class MultiplicationTable {
    public static void main(String[] args) {
        for (int i = 1; i <= 12; i++)
            System.out.print("\t" + i);
        
        System.out.println();
        for (int i = 0; i < 100; i++)
            System.out.print("-");
        System.out.println();
        for (int i = 1; i <= 12; i++) {
            System.out.print(i + "|");
            for(int j = 1; j <= 12; j++) {
                System.out.print("\t");
                if (j >= i)
                    System.out.print("\t" + i * j);
            }
            System.out.println();
        }
    }
}







Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed;  use Ada.Strings.Fixed;
procedure Multiplication_Table is
   package IO is new Integer_IO (Integer);
   use IO;
begin
   Put ("  | ");
   for Row in 1..12 loop
      Put (Row, Width => 4);
   end loop;
   New_Line;
   Put_Line ("
   for Row in 1..12 loop
      Put (Row, Width => 2);
      Put ("| ");
      for Column in 1..12 loop
         if Column < Row then
            Put ("    ");
         else
            Put (Row * Column, Width => 4);
         end if;
      end loop;
      New_Line;
   end loop;
end Multiplication_Table;
Task: Multiplication tables







Python: >>> size = 12
>>> width = len(str(size**2))
>>> for row in range(-1,size+1):
	if row==0:
		print("─"*width + "┼"+"─"*((width+1)*size-1))
	else:
		print("".join("%*s%1s" % ((width,) + (("x","│")      if row==-1 and col==0
					              else (row,"│") if row>0   and col==0
					              else (col,"")  if row==-1
					              else ("","")   if row>col
					              else (row*col,"")))
			       for col in range(size+1)))

		
  x│  1   2   3   4   5   6   7   8   9  10  11  12 
───┼───────────────────────────────────────────────
  1│  1   2   3   4   5   6   7   8   9  10  11  12 
  2│      4   6   8  10  12  14  16  18  20  22  24 
  3│          9  12  15  18  21  24  27  30  33  36 
  4│             16  20  24  28  32  36  40  44  48 
  5│                 25  30  35  40  45  50  55  60 
  6│                     36  42  48  54  60  66  72 
  7│                         49  56  63  70  77  84 
  8│                             64  72  80  88  96 
  9│                                 81  90  99 108 
 10│                                    100 110 120 
 11│                                        121 132 
 12│                                            144 
>>>





Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed;  use Ada.Strings.Fixed;
procedure Multiplication_Table is
   package IO is new Integer_IO (Integer);
   use IO;
begin
   Put ("  | ");
   for Row in 1..12 loop
      Put (Row, Width => 4);
   end loop;
   New_Line;
   Put_Line ("
   for Row in 1..12 loop
      Put (Row, Width => 2);
      Put ("| ");
      for Column in 1..12 loop
         if Column < Row then
            Put ("    ");
         else
            Put (Row * Column, Width => 4);
         end if;
      end loop;
      New_Line;
   end loop;
end Multiplication_Table;
Task: Multiplication tables








VB: Option Explicit

Sub Multiplication_Tables()
Dim strTemp As String, strBuff As String
Dim i&, j&, NbDigits As Byte


Const NB_END As Byte = 12

    Select Case NB_END
        Case Is < 10: NbDigits = 3
        Case 10 To 31: NbDigits = 4
        Case 31 To 100: NbDigits = 5
        Case Else: MsgBox "Number too large": Exit Sub
    End Select
    strBuff = String(NbDigits, " ")
    
    For i = 1 To NB_END
        strTemp = Right(strBuff & i, NbDigits)
        For j = 2 To NB_END
            If j < i Then
                strTemp = strTemp & strBuff
            Else
                strTemp = strTemp & Right(strBuff & j * i, NbDigits)
            End If
        Next j
        Debug.Print strTemp
    Next i
End Sub




Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Fixed;  use Ada.Strings.Fixed;
procedure Multiplication_Table is
   package IO is new Integer_IO (Integer);
   use IO;
begin
   Put ("  | ");
   for Row in 1..12 loop
      Put (Row, Width => 4);
   end loop;
   New_Line;
   Put_Line ("
   for Row in 1..12 loop
      Put (Row, Width => 2);
      Put ("| ");
      for Column in 1..12 loop
         if Column < Row then
            Put ("    ");
         else
            Put (Row * Column, Width => 4);
         end if;
      end loop;
      New_Line;
   end loop;
end Multiplication_Table;
Task: Multiplication tables

C: #include <stdio.h>

int main(void)
{
	int i, j, n = 12;
 
	for (j = 1; j <= n; j++) printf("%3d%c", j, j != n ? ' ' : '\n');
	for (j = 0; j <= n; j++) printf(j != n ? "----" : "+\n");

	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++)
			printf(j < i ? "    " : "%3d ", i * j);
                printf("| %d\n", i);
        }
 
	return 0;
}
Task: Multiplication tables



C#: using System;

namespace multtbl
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write(" X".PadRight(4));
            for (int i = 1; i <= 12; i++)
                Console.Write(i.ToString("####").PadLeft(4));

            Console.WriteLine();
            Console.Write(" ___");

            for (int i = 1; i <= 12; i++)
                Console.Write(" ___");

            Console.WriteLine();
            for (int row = 1; row <= 12; row++)
            {
                Console.Write(row.ToString("###").PadLeft(3).PadRight(4));
                for (int col = 1; col <= 12; col++)
                {
                    if (row <= col)
                        Console.Write((row * col).ToString("###").PadLeft(4));
                    else
                        Console.Write("".PadLeft(4));
                }

                Console.WriteLine();
            }

            Console.WriteLine();
            Console.ReadLine();
        }
    }
}
Task: Multiplication tables


C++: #include <iostream>
#include <iomanip>
#include <cmath> 
#include <algorithm> 

size_t table_column_width(const int min, const int max)
{
    unsigned int abs_max = std::max(max*max, min*min);

    
    
    
    
    size_t colwidth = 2 + std::log10(abs_max);

    
    
    
    if (min < 0 && max > 0)
	++colwidth;
    return colwidth;
}

struct Writer_
{
    decltype(std::setw(1)) fmt_;
    Writer_(size_t w) : fmt_(std::setw(w)) {}
    template<class T_> Writer_& operator()(const T_& info) { std::cout << fmt_ << info; return *this; }
};

void print_table_header(const int min, const int max)
{
    Writer_ write(table_column_width(min, max));

    
    write(" ");
    for(int col = min; col <= max; ++col)
        write(col);

    
    std::cout << std::endl << std::endl;
}

void print_table_row(const int num, const int min, const int max)
{
    Writer_ write(table_column_width(min, max));

    
    write(num);

    
    for(int multiplicand = min; multiplicand < num; ++multiplicand)
        write(" ");

    
    for(int multiplicand = num; multiplicand <= max; ++multiplicand)
        write(num * multiplicand);

    
    std::cout << std::endl << std::endl;
}

void print_table(const int min, const int max)
{
    
    print_table_header(min, max);

    
    for(int row = min; row <= max; ++row)
        print_table_row(row, min, max);
}

int main()
{
    print_table(1, 12);
    return 0;
}
Task: Multiplication tables





Java: public class MultiplicationTable {
    public static void main(String[] args) {
        for (int i = 1; i <= 12; i++)
            System.out.print("\t" + i);
        
        System.out.println();
        for (int i = 0; i < 100; i++)
            System.out.print("-");
        System.out.println();
        for (int i = 1; i <= 12; i++) {
            System.out.print(i + "|");
            for(int j = 1; j <= 12; j++) {
                System.out.print("\t");
                if (j >= i)
                    System.out.print("\t" + i * j);
            }
            System.out.println();
        }
    }
}
Task: Multiplication tables







Python: >>> size = 12
>>> width = len(str(size**2))
>>> for row in range(-1,size+1):
	if row==0:
		print("─"*width + "┼"+"─"*((width+1)*size-1))
	else:
		print("".join("%*s%1s" % ((width,) + (("x","│")      if row==-1 and col==0
					              else (row,"│") if row>0   and col==0
					              else (col,"")  if row==-1
					              else ("","")   if row>col
					              else (row*col,"")))
			       for col in range(size+1)))

		
  x│  1   2   3   4   5   6   7   8   9  10  11  12 
───┼───────────────────────────────────────────────
  1│  1   2   3   4   5   6   7   8   9  10  11  12 
  2│      4   6   8  10  12  14  16  18  20  22  24 
  3│          9  12  15  18  21  24  27  30  33  36 
  4│             16  20  24  28  32  36  40  44  48 
  5│                 25  30  35  40  45  50  55  60 
  6│                     36  42  48  54  60  66  72 
  7│                         49  56  63  70  77  84 
  8│                             64  72  80  88  96 
  9│                                 81  90  99 108 
 10│                                    100 110 120 
 11│                                        121 132 
 12│                                            144 
>>>
Task: Multiplication tables








VB: Option Explicit

Sub Multiplication_Tables()
Dim strTemp As String, strBuff As String
Dim i&, j&, NbDigits As Byte


Const NB_END As Byte = 12

    Select Case NB_END
        Case Is < 10: NbDigits = 3
        Case 10 To 31: NbDigits = 4
        Case 31 To 100: NbDigits = 5
        Case Else: MsgBox "Number too large": Exit Sub
    End Select
    strBuff = String(NbDigits, " ")
    
    For i = 1 To NB_END
        strTemp = Right(strBuff & i, NbDigits)
        For j = 2 To NB_END
            If j < i Then
                strTemp = strTemp & strBuff
            Else
                strTemp = strTemp & Right(strBuff & j * i, NbDigits)
            End If
        Next j
        Debug.Print strTemp
    Next i
End Sub
Task: Multiplication tables




Go: package main

import (
    "fmt"
)

func main() {
    fmt.Print(" x |")
    for i := 1; i <= 12; i++ {
        fmt.Printf("%4d", i)
    }
    fmt.Print("\n---+")
    for i := 1; i <= 12; i++ {
        fmt.Print("----")
    }
    for j := 1; j <= 12; j++ {
        fmt.Printf("\n%2d |", j)
        for i := 1; i <= 12; i++ {
            if i >= j {
                fmt.Printf("%4d", i*j)
            } else {
                fmt.Print("    ")
            }
        }
    }
    fmt.Println("")
}