WeixiangYan/CodeTransOcean huggingface dataset:
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();
        }
    }
}








Fortran: program multtable
implicit none

  integer :: i, j, k

    write(*, "(a)") " x|   1   2   3   4   5   6   7   8   9  10  11  12"
    write(*, "(a)") "--+------------------------------------------------"
    do i = 1, 12
      write(*, "(i2, a)", advance="no") i, "|"
	do k = 2, i
    	  write(*, "(a4)", advance="no") ""
        end do
    	do j = i, 12
          write(*, "(i4)", advance="no") i*j
        end do
        write(*, *)
    end do

end program multtable
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;
}









Fortran: program multtable
implicit none

  integer :: i, j, k

    write(*, "(a)") " x|   1   2   3   4   5   6   7   8   9  10  11  12"
    write(*, "(a)") "--+------------------------------------------------"
    do i = 1, 12
      write(*, "(i2, a)", advance="no") i, "|"
	do k = 2, i
    	  write(*, "(a4)", advance="no") ""
        end do
    	do j = i, 12
          write(*, "(i4)", advance="no") i*j
        end do
        write(*, *)
    end do

end program multtable
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;
}










Fortran: program multtable
implicit none

  integer :: i, j, k

    write(*, "(a)") " x|   1   2   3   4   5   6   7   8   9  10  11  12"
    write(*, "(a)") "--+------------------------------------------------"
    do i = 1, 12
      write(*, "(i2, a)", advance="no") i, "|"
	do k = 2, i
    	  write(*, "(a4)", advance="no") ""
        end do
    	do j = i, 12
          write(*, "(i4)", advance="no") i*j
        end do
        write(*, *)
    end do

end program multtable
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();
        }
    }
}






Fortran: program multtable
implicit none

  integer :: i, j, k

    write(*, "(a)") " x|   1   2   3   4   5   6   7   8   9  10  11  12"
    write(*, "(a)") "--+------------------------------------------------"
    do i = 1, 12
      write(*, "(i2, a)", advance="no") i, "|"
	do k = 2, i
    	  write(*, "(a4)", advance="no") ""
        end do
    	do j = i, 12
          write(*, "(i4)", advance="no") i*j
        end do
        write(*, *)
    end do

end program multtable
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 
>>>




Fortran: program multtable
implicit none

  integer :: i, j, k

    write(*, "(a)") " x|   1   2   3   4   5   6   7   8   9  10  11  12"
    write(*, "(a)") "--+------------------------------------------------"
    do i = 1, 12
      write(*, "(i2, a)", advance="no") i, "|"
	do k = 2, i
    	  write(*, "(a4)", advance="no") ""
        end do
    	do j = i, 12
          write(*, "(i4)", advance="no") i*j
        end do
        write(*, *)
    end do

end program multtable
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



Fortran: program multtable
implicit none

  integer :: i, j, k

    write(*, "(a)") " x|   1   2   3   4   5   6   7   8   9  10  11  12"
    write(*, "(a)") "--+------------------------------------------------"
    do i = 1, 12
      write(*, "(i2, a)", advance="no") i, "|"
	do k = 2, i
    	  write(*, "(a4)", advance="no") ""
        end do
    	do j = i, 12
          write(*, "(i4)", advance="no") i*j
        end do
        write(*, *)
    end do

end program multtable
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;
}









COBOL:        identification division.
       program-id. multiplication-table.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 multiplication.
          05 rows occurs 12 times.
             10 colm occurs 12 times.
                15 num    pic 999.
       77 cand pic 99.
       77 ier  pic 99.
       77 ind  pic z9.
       77 show pic zz9.

       procedure division.
       sample-main.
       perform varying cand from 1 by 1 until cand greater than 12
                  after ier from 1 by 1 until ier greater than 12
           multiply cand by ier giving num(cand, ier)
       end-perform

       perform varying cand from 1 by 1 until cand greater than 12
           move cand to ind
           display "x " ind "| " with no advancing
           perform varying ier from 1 by 1 until ier greater than 12
               if ier greater than or equal to cand then
                   move num(cand, ier) to show
                   display show with no advancing
                   if ier equal to 12 then
                       display "|"
                   else
                       display space with no advancing
                   end-if
               else
                   display "    " with no advancing
               end-if
           end-perform
       end-perform

       goback.
       end program multiplication-table.
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();
        }
    }
}







COBOL:        identification division.
       program-id. multiplication-table.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 multiplication.
          05 rows occurs 12 times.
             10 colm occurs 12 times.
                15 num    pic 999.
       77 cand pic 99.
       77 ier  pic 99.
       77 ind  pic z9.
       77 show pic zz9.

       procedure division.
       sample-main.
       perform varying cand from 1 by 1 until cand greater than 12
                  after ier from 1 by 1 until ier greater than 12
           multiply cand by ier giving num(cand, ier)
       end-perform

       perform varying cand from 1 by 1 until cand greater than 12
           move cand to ind
           display "x " ind "| " with no advancing
           perform varying ier from 1 by 1 until ier greater than 12
               if ier greater than or equal to cand then
                   move num(cand, ier) to show
                   display show with no advancing
                   if ier equal to 12 then
                       display "|"
                   else
                       display space with no advancing
                   end-if
               else
                   display "    " with no advancing
               end-if
           end-perform
       end-perform

       goback.
       end program 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;
}








COBOL:        identification division.
       program-id. multiplication-table.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 multiplication.
          05 rows occurs 12 times.
             10 colm occurs 12 times.
                15 num    pic 999.
       77 cand pic 99.
       77 ier  pic 99.
       77 ind  pic z9.
       77 show pic zz9.

       procedure division.
       sample-main.
       perform varying cand from 1 by 1 until cand greater than 12
                  after ier from 1 by 1 until ier greater than 12
           multiply cand by ier giving num(cand, ier)
       end-perform

       perform varying cand from 1 by 1 until cand greater than 12
           move cand to ind
           display "x " ind "| " with no advancing
           perform varying ier from 1 by 1 until ier greater than 12
               if ier greater than or equal to cand then
                   move num(cand, ier) to show
                   display show with no advancing
                   if ier equal to 12 then
                       display "|"
                   else
                       display space with no advancing
                   end-if
               else
                   display "    " with no advancing
               end-if
           end-perform
       end-perform

       goback.
       end program 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();
        }
    }
}





COBOL:        identification division.
       program-id. multiplication-table.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 multiplication.
          05 rows occurs 12 times.
             10 colm occurs 12 times.
                15 num    pic 999.
       77 cand pic 99.
       77 ier  pic 99.
       77 ind  pic z9.
       77 show pic zz9.

       procedure division.
       sample-main.
       perform varying cand from 1 by 1 until cand greater than 12
                  after ier from 1 by 1 until ier greater than 12
           multiply cand by ier giving num(cand, ier)
       end-perform

       perform varying cand from 1 by 1 until cand greater than 12
           move cand to ind
           display "x " ind "| " with no advancing
           perform varying ier from 1 by 1 until ier greater than 12
               if ier greater than or equal to cand then
                   move num(cand, ier) to show
                   display show with no advancing
                   if ier equal to 12 then
                       display "|"
                   else
                       display space with no advancing
                   end-if
               else
                   display "    " with no advancing
               end-if
           end-perform
       end-perform

       goback.
       end program 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 
>>>



COBOL:        identification division.
       program-id. multiplication-table.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 multiplication.
          05 rows occurs 12 times.
             10 colm occurs 12 times.
                15 num    pic 999.
       77 cand pic 99.
       77 ier  pic 99.
       77 ind  pic z9.
       77 show pic zz9.

       procedure division.
       sample-main.
       perform varying cand from 1 by 1 until cand greater than 12
                  after ier from 1 by 1 until ier greater than 12
           multiply cand by ier giving num(cand, ier)
       end-perform

       perform varying cand from 1 by 1 until cand greater than 12
           move cand to ind
           display "x " ind "| " with no advancing
           perform varying ier from 1 by 1 until ier greater than 12
               if ier greater than or equal to cand then
                   move num(cand, ier) to show
                   display show with no advancing
                   if ier equal to 12 then
                       display "|"
                   else
                       display space with no advancing
                   end-if
               else
                   display "    " with no advancing
               end-if
           end-perform
       end-perform

       goback.
       end program 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


COBOL:        identification division.
       program-id. multiplication-table.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 multiplication.
          05 rows occurs 12 times.
             10 colm occurs 12 times.
                15 num    pic 999.
       77 cand pic 99.
       77 ier  pic 99.
       77 ind  pic z9.
       77 show pic zz9.

       procedure division.
       sample-main.
       perform varying cand from 1 by 1 until cand greater than 12
                  after ier from 1 by 1 until ier greater than 12
           multiply cand by ier giving num(cand, ier)
       end-perform

       perform varying cand from 1 by 1 until cand greater than 12
           move cand to ind
           display "x " ind "| " with no advancing
           perform varying ier from 1 by 1 until ier greater than 12
               if ier greater than or equal to cand then
                   move num(cand, ier) to show
                   display show with no advancing
                   if ier equal to 12 then
                       display "|"
                   else
                       display space with no advancing
                   end-if
               else
                   display "    " with no advancing
               end-if
           end-perform
       end-perform

       goback.
       end program multiplication-table.