Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Rewrite this program in C++ while keeping its functionality equivalent to the Lua version. | function multiply(n, a, b) if a <= b then return n, multiply(n, a + 1, b) end end
a, b = io.read() + 0, io.read() + 0
matrix = {multiply({multiply(1, 1, b)}, 1, a)}
matrix[a][b] = 5
print(matrix[a][b])
print(matrix[1][1])
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Translate the given Lua code snippet into Java without altering its behavior. | function multiply(n, a, b) if a <= b then return n, multiply(n, a + 1, b) end end
a, b = io.read() + 0, io.read() + 0
matrix = {multiply({multiply(1, 1, b)}, 1, a)}
matrix[a][b] = 5
print(matrix[a][b])
print(matrix[1][1])
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Port the provided Lua code into Python while preserving the original functionality. | function multiply(n, a, b) if a <= b then return n, multiply(n, a + 1, b) end end
a, b = io.read() + 0, io.read() + 0
matrix = {multiply({multiply(1, 1, b)}, 1, a)}
matrix[a][b] = 5
print(matrix[a][b])
print(matrix[1][1])
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Translate this program into VB but keep the logic exactly as in Lua. | function multiply(n, a, b) if a <= b then return n, multiply(n, a + 1, b) end end
a, b = io.read() + 0, io.read() + 0
matrix = {multiply({multiply(1, 1, b)}, 1, a)}
matrix[a][b] = 5
print(matrix[a][b])
print(matrix[1][1])
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Produce a language-to-language conversion: from Lua to Go, same semantics. | function multiply(n, a, b) if a <= b then return n, multiply(n, a + 1, b) end end
a, b = io.read() + 0, io.read() + 0
matrix = {multiply({multiply(1, 1, b)}, 1, a)}
matrix[a][b] = 5
print(matrix[a][b])
print(matrix[1][1])
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Maintain the same structure and functionality when rewriting this code in C. | arrayFun[m_Integer,n_Integer]:=Module[{array=ConstantArray[0,{m,n}]},
array[[1,1]]=RandomReal[];
array[[1,1]]
]
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Rewrite the snippet below in C# so it works the same as the original Mathematica code. | arrayFun[m_Integer,n_Integer]:=Module[{array=ConstantArray[0,{m,n}]},
array[[1,1]]=RandomReal[];
array[[1,1]]
]
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Produce a functionally identical C++ code for the snippet given in Mathematica. | arrayFun[m_Integer,n_Integer]:=Module[{array=ConstantArray[0,{m,n}]},
array[[1,1]]=RandomReal[];
array[[1,1]]
]
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Change the programming language of this snippet from Mathematica to Java without modifying what it does. | arrayFun[m_Integer,n_Integer]:=Module[{array=ConstantArray[0,{m,n}]},
array[[1,1]]=RandomReal[];
array[[1,1]]
]
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Convert this Mathematica snippet to Python and keep its semantics consistent. | arrayFun[m_Integer,n_Integer]:=Module[{array=ConstantArray[0,{m,n}]},
array[[1,1]]=RandomReal[];
array[[1,1]]
]
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Convert the following code from Mathematica to VB, ensuring the logic remains intact. | arrayFun[m_Integer,n_Integer]:=Module[{array=ConstantArray[0,{m,n}]},
array[[1,1]]=RandomReal[];
array[[1,1]]
]
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Can you help me rewrite this code in Go instead of Mathematica, keeping it the same logically? | arrayFun[m_Integer,n_Integer]:=Module[{array=ConstantArray[0,{m,n}]},
array[[1,1]]=RandomReal[];
array[[1,1]]
]
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Can you help me rewrite this code in C instead of MATLAB, keeping it the same logically? | width = input('Array Width: ');
height = input('Array Height: ');
array = zeros(width,height);
array(1,1) = 12;
disp(['Array element (1,1) = ' num2str(array(1,1))]);
clear array;
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Write the same code in C# as shown below in MATLAB. | width = input('Array Width: ');
height = input('Array Height: ');
array = zeros(width,height);
array(1,1) = 12;
disp(['Array element (1,1) = ' num2str(array(1,1))]);
clear array;
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Port the following code from MATLAB to C++ with equivalent syntax and logic. | width = input('Array Width: ');
height = input('Array Height: ');
array = zeros(width,height);
array(1,1) = 12;
disp(['Array element (1,1) = ' num2str(array(1,1))]);
clear array;
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Produce a functionally identical Java code for the snippet given in MATLAB. | width = input('Array Width: ');
height = input('Array Height: ');
array = zeros(width,height);
array(1,1) = 12;
disp(['Array element (1,1) = ' num2str(array(1,1))]);
clear array;
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Rewrite this program in Python while keeping its functionality equivalent to the MATLAB version. | width = input('Array Width: ');
height = input('Array Height: ');
array = zeros(width,height);
array(1,1) = 12;
disp(['Array element (1,1) = ' num2str(array(1,1))]);
clear array;
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Ensure the translated VB code behaves exactly like the original MATLAB snippet. | width = input('Array Width: ');
height = input('Array Height: ');
array = zeros(width,height);
array(1,1) = 12;
disp(['Array element (1,1) = ' num2str(array(1,1))]);
clear array;
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Convert this MATLAB block to Go, preserving its control flow and logic. | width = input('Array Width: ');
height = input('Array Height: ');
array = zeros(width,height);
array(1,1) = 12;
disp(['Array element (1,1) = ' num2str(array(1,1))]);
clear array;
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Ensure the translated C code behaves exactly like the original Nim snippet. | import strutils, rdstdin
let
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
var s = newSeq[seq[int]](h)
for i in 0 ..< h:
s[i].newSeq(w)
s[0][0] = 5
echo s[0][0]
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Please provide an equivalent version of this Nim code in C#. | import strutils, rdstdin
let
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
var s = newSeq[seq[int]](h)
for i in 0 ..< h:
s[i].newSeq(w)
s[0][0] = 5
echo s[0][0]
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Port the following code from Nim to C++ with equivalent syntax and logic. | import strutils, rdstdin
let
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
var s = newSeq[seq[int]](h)
for i in 0 ..< h:
s[i].newSeq(w)
s[0][0] = 5
echo s[0][0]
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Transform the following Nim implementation into Java, maintaining the same output and logic. | import strutils, rdstdin
let
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
var s = newSeq[seq[int]](h)
for i in 0 ..< h:
s[i].newSeq(w)
s[0][0] = 5
echo s[0][0]
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Change the following Nim code into Python without altering its purpose. | import strutils, rdstdin
let
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
var s = newSeq[seq[int]](h)
for i in 0 ..< h:
s[i].newSeq(w)
s[0][0] = 5
echo s[0][0]
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Change the following Nim code into VB without altering its purpose. | import strutils, rdstdin
let
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
var s = newSeq[seq[int]](h)
for i in 0 ..< h:
s[i].newSeq(w)
s[0][0] = 5
echo s[0][0]
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Transform the following Nim implementation into Go, maintaining the same output and logic. | import strutils, rdstdin
let
w = readLineFromStdin("Width: ").parseInt()
h = readLineFromStdin("Height: ").parseInt()
var s = newSeq[seq[int]](h)
for i in 0 ..< h:
s[i].newSeq(w)
s[0][0] = 5
echo s[0][0]
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Rewrite this program in C while keeping its functionality equivalent to the OCaml version. | let nbr1 = read_int ();;
let nbr2 = read_int ();;
let array = Array.make_matrix nbr1 nbr2 0.0;;
array.(0).(0) <- 3.5;;
print_float array.(0).(0); print_newline ();;
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Convert this OCaml snippet to C# and keep its semantics consistent. | let nbr1 = read_int ();;
let nbr2 = read_int ();;
let array = Array.make_matrix nbr1 nbr2 0.0;;
array.(0).(0) <- 3.5;;
print_float array.(0).(0); print_newline ();;
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Rewrite this program in C++ while keeping its functionality equivalent to the OCaml version. | let nbr1 = read_int ();;
let nbr2 = read_int ();;
let array = Array.make_matrix nbr1 nbr2 0.0;;
array.(0).(0) <- 3.5;;
print_float array.(0).(0); print_newline ();;
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Convert this OCaml snippet to Java and keep its semantics consistent. | let nbr1 = read_int ();;
let nbr2 = read_int ();;
let array = Array.make_matrix nbr1 nbr2 0.0;;
array.(0).(0) <- 3.5;;
print_float array.(0).(0); print_newline ();;
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Generate an equivalent Python version of this OCaml code. | let nbr1 = read_int ();;
let nbr2 = read_int ();;
let array = Array.make_matrix nbr1 nbr2 0.0;;
array.(0).(0) <- 3.5;;
print_float array.(0).(0); print_newline ();;
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Translate this program into VB but keep the logic exactly as in OCaml. | let nbr1 = read_int ();;
let nbr2 = read_int ();;
let array = Array.make_matrix nbr1 nbr2 0.0;;
array.(0).(0) <- 3.5;;
print_float array.(0).(0); print_newline ();;
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Transform the following OCaml implementation into Go, maintaining the same output and logic. | let nbr1 = read_int ();;
let nbr2 = read_int ();;
let array = Array.make_matrix nbr1 nbr2 0.0;;
array.(0).(0) <- 3.5;;
print_float array.(0).(0); print_newline ();;
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Produce a functionally identical C code for the snippet given in Pascal. | program array2d(input, output);
type
tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real;
pArray2D = ^tArray2D;
var
d1, d2: integer;
data: pArray2D;
begin
readln(d1, d2);
new(data, d1, d2);
data^[1,1] := 3.5;
writeln(data^[1,1]);
dispose(data);
end.
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Translate the given Pascal code snippet into C# without altering its behavior. | program array2d(input, output);
type
tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real;
pArray2D = ^tArray2D;
var
d1, d2: integer;
data: pArray2D;
begin
readln(d1, d2);
new(data, d1, d2);
data^[1,1] := 3.5;
writeln(data^[1,1]);
dispose(data);
end.
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Ensure the translated C++ code behaves exactly like the original Pascal snippet. | program array2d(input, output);
type
tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real;
pArray2D = ^tArray2D;
var
d1, d2: integer;
data: pArray2D;
begin
readln(d1, d2);
new(data, d1, d2);
data^[1,1] := 3.5;
writeln(data^[1,1]);
dispose(data);
end.
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Write the same algorithm in Java as shown in this Pascal implementation. | program array2d(input, output);
type
tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real;
pArray2D = ^tArray2D;
var
d1, d2: integer;
data: pArray2D;
begin
readln(d1, d2);
new(data, d1, d2);
data^[1,1] := 3.5;
writeln(data^[1,1]);
dispose(data);
end.
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Change the programming language of this snippet from Pascal to Python without modifying what it does. | program array2d(input, output);
type
tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real;
pArray2D = ^tArray2D;
var
d1, d2: integer;
data: pArray2D;
begin
readln(d1, d2);
new(data, d1, d2);
data^[1,1] := 3.5;
writeln(data^[1,1]);
dispose(data);
end.
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Generate a VB translation of this Pascal snippet without changing its computational steps. | program array2d(input, output);
type
tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real;
pArray2D = ^tArray2D;
var
d1, d2: integer;
data: pArray2D;
begin
readln(d1, d2);
new(data, d1, d2);
data^[1,1] := 3.5;
writeln(data^[1,1]);
dispose(data);
end.
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Keep all operations the same but rewrite the snippet in Go. | program array2d(input, output);
type
tArray2d(dim1, dim2: integer) = array[1 .. dim1, 1 .. dim2] of real;
pArray2D = ^tArray2D;
var
d1, d2: integer;
data: pArray2D;
begin
readln(d1, d2);
new(data, d1, d2);
data^[1,1] := 3.5;
writeln(data^[1,1]);
dispose(data);
end.
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Produce a functionally identical C code for the snippet given in Perl. | sub make_array($ $){
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
my @array;
$array[0][0] = 'X ';
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x);
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x);
foreach my $dy (0 .. $y){
foreach my $dx (0 .. $x){
(defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
}
print "\n";
}
}
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Transform the following Perl implementation into C#, maintaining the same output and logic. | sub make_array($ $){
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
my @array;
$array[0][0] = 'X ';
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x);
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x);
foreach my $dy (0 .. $y){
foreach my $dx (0 .. $x){
(defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
}
print "\n";
}
}
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Rewrite the snippet below in C++ so it works the same as the original Perl code. | sub make_array($ $){
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
my @array;
$array[0][0] = 'X ';
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x);
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x);
foreach my $dy (0 .. $y){
foreach my $dx (0 .. $x){
(defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
}
print "\n";
}
}
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in Java. | sub make_array($ $){
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
my @array;
$array[0][0] = 'X ';
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x);
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x);
foreach my $dy (0 .. $y){
foreach my $dx (0 .. $x){
(defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
}
print "\n";
}
}
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Generate an equivalent Python version of this Perl code. | sub make_array($ $){
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
my @array;
$array[0][0] = 'X ';
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x);
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x);
foreach my $dy (0 .. $y){
foreach my $dx (0 .. $x){
(defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
}
print "\n";
}
}
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Write a version of this Perl function in VB with identical behavior. | sub make_array($ $){
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
my @array;
$array[0][0] = 'X ';
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x);
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x);
foreach my $dy (0 .. $y){
foreach my $dx (0 .. $x){
(defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
}
print "\n";
}
}
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Produce a functionally identical Go code for the snippet given in Perl. | sub make_array($ $){
my $x = ($_[0] =~ /^\d+$/) ? shift : 0;
my $y = ($_[0] =~ /^\d+$/) ? shift : 0;
my @array;
$array[0][0] = 'X ';
$array[5][7] = 'X ' if (5 <= $y and 7 <= $x);
$array[12][15] = 'X ' if (12 <= $y and 15 <= $x);
foreach my $dy (0 .. $y){
foreach my $dx (0 .. $x){
(defined $array[$dy][$dx]) ? (print $array[$dy][$dx]) : (print '. ');
}
print "\n";
}
}
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Port the provided PowerShell code into C while preserving the original functionality. | function Read-ArrayIndex ([string]$Prompt = "Enter an integer greater than zero")
{
[int]$inputAsInteger = 0
while (-not [Int]::TryParse(([string]$inputString = Read-Host $Prompt), [ref]$inputAsInteger))
{
$inputString = Read-Host "Enter an integer greater than zero"
}
if ($inputAsInteger -gt 0) {return $inputAsInteger} else {return 1}
}
$x = $y = $null
do
{
if ($x -eq $null) {$x = Read-ArrayIndex -Prompt "Enter two dimensional array index X"}
if ($y -eq $null) {$y = Read-ArrayIndex -Prompt "Enter two dimensional array index Y"}
}
until (($x -ne $null) -and ($y -ne $null))
$array2d = New-Object -TypeName 'System.Object[,]' -ArgumentList $x, $y
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Produce a language-to-language conversion: from PowerShell to C#, same semantics. | function Read-ArrayIndex ([string]$Prompt = "Enter an integer greater than zero")
{
[int]$inputAsInteger = 0
while (-not [Int]::TryParse(([string]$inputString = Read-Host $Prompt), [ref]$inputAsInteger))
{
$inputString = Read-Host "Enter an integer greater than zero"
}
if ($inputAsInteger -gt 0) {return $inputAsInteger} else {return 1}
}
$x = $y = $null
do
{
if ($x -eq $null) {$x = Read-ArrayIndex -Prompt "Enter two dimensional array index X"}
if ($y -eq $null) {$y = Read-ArrayIndex -Prompt "Enter two dimensional array index Y"}
}
until (($x -ne $null) -and ($y -ne $null))
$array2d = New-Object -TypeName 'System.Object[,]' -ArgumentList $x, $y
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Rewrite this program in C++ while keeping its functionality equivalent to the PowerShell version. | function Read-ArrayIndex ([string]$Prompt = "Enter an integer greater than zero")
{
[int]$inputAsInteger = 0
while (-not [Int]::TryParse(([string]$inputString = Read-Host $Prompt), [ref]$inputAsInteger))
{
$inputString = Read-Host "Enter an integer greater than zero"
}
if ($inputAsInteger -gt 0) {return $inputAsInteger} else {return 1}
}
$x = $y = $null
do
{
if ($x -eq $null) {$x = Read-ArrayIndex -Prompt "Enter two dimensional array index X"}
if ($y -eq $null) {$y = Read-ArrayIndex -Prompt "Enter two dimensional array index Y"}
}
until (($x -ne $null) -and ($y -ne $null))
$array2d = New-Object -TypeName 'System.Object[,]' -ArgumentList $x, $y
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Preserve the algorithm and functionality while converting the code from PowerShell to Java. | function Read-ArrayIndex ([string]$Prompt = "Enter an integer greater than zero")
{
[int]$inputAsInteger = 0
while (-not [Int]::TryParse(([string]$inputString = Read-Host $Prompt), [ref]$inputAsInteger))
{
$inputString = Read-Host "Enter an integer greater than zero"
}
if ($inputAsInteger -gt 0) {return $inputAsInteger} else {return 1}
}
$x = $y = $null
do
{
if ($x -eq $null) {$x = Read-ArrayIndex -Prompt "Enter two dimensional array index X"}
if ($y -eq $null) {$y = Read-ArrayIndex -Prompt "Enter two dimensional array index Y"}
}
until (($x -ne $null) -and ($y -ne $null))
$array2d = New-Object -TypeName 'System.Object[,]' -ArgumentList $x, $y
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Ensure the translated Python code behaves exactly like the original PowerShell snippet. | function Read-ArrayIndex ([string]$Prompt = "Enter an integer greater than zero")
{
[int]$inputAsInteger = 0
while (-not [Int]::TryParse(([string]$inputString = Read-Host $Prompt), [ref]$inputAsInteger))
{
$inputString = Read-Host "Enter an integer greater than zero"
}
if ($inputAsInteger -gt 0) {return $inputAsInteger} else {return 1}
}
$x = $y = $null
do
{
if ($x -eq $null) {$x = Read-ArrayIndex -Prompt "Enter two dimensional array index X"}
if ($y -eq $null) {$y = Read-ArrayIndex -Prompt "Enter two dimensional array index Y"}
}
until (($x -ne $null) -and ($y -ne $null))
$array2d = New-Object -TypeName 'System.Object[,]' -ArgumentList $x, $y
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Write a version of this PowerShell function in VB with identical behavior. | function Read-ArrayIndex ([string]$Prompt = "Enter an integer greater than zero")
{
[int]$inputAsInteger = 0
while (-not [Int]::TryParse(([string]$inputString = Read-Host $Prompt), [ref]$inputAsInteger))
{
$inputString = Read-Host "Enter an integer greater than zero"
}
if ($inputAsInteger -gt 0) {return $inputAsInteger} else {return 1}
}
$x = $y = $null
do
{
if ($x -eq $null) {$x = Read-ArrayIndex -Prompt "Enter two dimensional array index X"}
if ($y -eq $null) {$y = Read-ArrayIndex -Prompt "Enter two dimensional array index Y"}
}
until (($x -ne $null) -and ($y -ne $null))
$array2d = New-Object -TypeName 'System.Object[,]' -ArgumentList $x, $y
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Generate an equivalent Go version of this PowerShell code. | function Read-ArrayIndex ([string]$Prompt = "Enter an integer greater than zero")
{
[int]$inputAsInteger = 0
while (-not [Int]::TryParse(([string]$inputString = Read-Host $Prompt), [ref]$inputAsInteger))
{
$inputString = Read-Host "Enter an integer greater than zero"
}
if ($inputAsInteger -gt 0) {return $inputAsInteger} else {return 1}
}
$x = $y = $null
do
{
if ($x -eq $null) {$x = Read-ArrayIndex -Prompt "Enter two dimensional array index X"}
if ($y -eq $null) {$y = Read-ArrayIndex -Prompt "Enter two dimensional array index Y"}
}
until (($x -ne $null) -and ($y -ne $null))
$array2d = New-Object -TypeName 'System.Object[,]' -ArgumentList $x, $y
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Rewrite this program in C while keeping its functionality equivalent to the R version. | input <- readline("Enter two integers. Space delimited, please: ")
dims <- as.numeric(strsplit(input, " ")[[1]])
arr <- array(dim=dims)
ii <- ceiling(dims[1]/2)
jj <- ceiling(dims[2]/2)
arr[ii, jj] <- sum(dims)
cat("array[", ii, ",", jj, "] is ", arr[ii, jj], "\n", sep="")
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Rewrite the snippet below in C# so it works the same as the original R code. | input <- readline("Enter two integers. Space delimited, please: ")
dims <- as.numeric(strsplit(input, " ")[[1]])
arr <- array(dim=dims)
ii <- ceiling(dims[1]/2)
jj <- ceiling(dims[2]/2)
arr[ii, jj] <- sum(dims)
cat("array[", ii, ",", jj, "] is ", arr[ii, jj], "\n", sep="")
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Produce a functionally identical C++ code for the snippet given in R. | input <- readline("Enter two integers. Space delimited, please: ")
dims <- as.numeric(strsplit(input, " ")[[1]])
arr <- array(dim=dims)
ii <- ceiling(dims[1]/2)
jj <- ceiling(dims[2]/2)
arr[ii, jj] <- sum(dims)
cat("array[", ii, ",", jj, "] is ", arr[ii, jj], "\n", sep="")
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Translate the given R code snippet into Java without altering its behavior. | input <- readline("Enter two integers. Space delimited, please: ")
dims <- as.numeric(strsplit(input, " ")[[1]])
arr <- array(dim=dims)
ii <- ceiling(dims[1]/2)
jj <- ceiling(dims[2]/2)
arr[ii, jj] <- sum(dims)
cat("array[", ii, ",", jj, "] is ", arr[ii, jj], "\n", sep="")
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Generate an equivalent Python version of this R code. | input <- readline("Enter two integers. Space delimited, please: ")
dims <- as.numeric(strsplit(input, " ")[[1]])
arr <- array(dim=dims)
ii <- ceiling(dims[1]/2)
jj <- ceiling(dims[2]/2)
arr[ii, jj] <- sum(dims)
cat("array[", ii, ",", jj, "] is ", arr[ii, jj], "\n", sep="")
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Can you help me rewrite this code in VB instead of R, keeping it the same logically? | input <- readline("Enter two integers. Space delimited, please: ")
dims <- as.numeric(strsplit(input, " ")[[1]])
arr <- array(dim=dims)
ii <- ceiling(dims[1]/2)
jj <- ceiling(dims[2]/2)
arr[ii, jj] <- sum(dims)
cat("array[", ii, ",", jj, "] is ", arr[ii, jj], "\n", sep="")
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Translate this program into Go but keep the logic exactly as in R. | input <- readline("Enter two integers. Space delimited, please: ")
dims <- as.numeric(strsplit(input, " ")[[1]])
arr <- array(dim=dims)
ii <- ceiling(dims[1]/2)
jj <- ceiling(dims[2]/2)
arr[ii, jj] <- sum(dims)
cat("array[", ii, ",", jj, "] is ", arr[ii, jj], "\n", sep="")
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Write the same algorithm in C as shown in this Racket implementation. | #lang racket
(printf "Enter XY dimensions: ")
(define xy (cons (read) (read)))
(define array (for/vector ([x (car xy)]) (for/vector ([y (cdr xy)]) 0)))
(printf "Enter a number for the top-left: ")
(vector-set! (vector-ref array 0) 0 (read))
(printf "Enter a number for the bottom-right: ")
(vector-set! (vector-ref array (sub1 (car xy))) (sub1 (cdr xy)) (read))
array
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Preserve the algorithm and functionality while converting the code from Racket to C#. | #lang racket
(printf "Enter XY dimensions: ")
(define xy (cons (read) (read)))
(define array (for/vector ([x (car xy)]) (for/vector ([y (cdr xy)]) 0)))
(printf "Enter a number for the top-left: ")
(vector-set! (vector-ref array 0) 0 (read))
(printf "Enter a number for the bottom-right: ")
(vector-set! (vector-ref array (sub1 (car xy))) (sub1 (cdr xy)) (read))
array
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Rewrite this program in C++ while keeping its functionality equivalent to the Racket version. | #lang racket
(printf "Enter XY dimensions: ")
(define xy (cons (read) (read)))
(define array (for/vector ([x (car xy)]) (for/vector ([y (cdr xy)]) 0)))
(printf "Enter a number for the top-left: ")
(vector-set! (vector-ref array 0) 0 (read))
(printf "Enter a number for the bottom-right: ")
(vector-set! (vector-ref array (sub1 (car xy))) (sub1 (cdr xy)) (read))
array
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Convert the following code from Racket to Java, ensuring the logic remains intact. | #lang racket
(printf "Enter XY dimensions: ")
(define xy (cons (read) (read)))
(define array (for/vector ([x (car xy)]) (for/vector ([y (cdr xy)]) 0)))
(printf "Enter a number for the top-left: ")
(vector-set! (vector-ref array 0) 0 (read))
(printf "Enter a number for the bottom-right: ")
(vector-set! (vector-ref array (sub1 (car xy))) (sub1 (cdr xy)) (read))
array
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Write a version of this Racket function in Python with identical behavior. | #lang racket
(printf "Enter XY dimensions: ")
(define xy (cons (read) (read)))
(define array (for/vector ([x (car xy)]) (for/vector ([y (cdr xy)]) 0)))
(printf "Enter a number for the top-left: ")
(vector-set! (vector-ref array 0) 0 (read))
(printf "Enter a number for the bottom-right: ")
(vector-set! (vector-ref array (sub1 (car xy))) (sub1 (cdr xy)) (read))
array
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Port the provided Racket code into VB while preserving the original functionality. | #lang racket
(printf "Enter XY dimensions: ")
(define xy (cons (read) (read)))
(define array (for/vector ([x (car xy)]) (for/vector ([y (cdr xy)]) 0)))
(printf "Enter a number for the top-left: ")
(vector-set! (vector-ref array 0) 0 (read))
(printf "Enter a number for the bottom-right: ")
(vector-set! (vector-ref array (sub1 (car xy))) (sub1 (cdr xy)) (read))
array
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Produce a language-to-language conversion: from Racket to Go, same semantics. | #lang racket
(printf "Enter XY dimensions: ")
(define xy (cons (read) (read)))
(define array (for/vector ([x (car xy)]) (for/vector ([y (cdr xy)]) 0)))
(printf "Enter a number for the top-left: ")
(vector-set! (vector-ref array 0) 0 (read))
(printf "Enter a number for the bottom-right: ")
(vector-set! (vector-ref array (sub1 (car xy))) (sub1 (cdr xy)) (read))
array
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Maintain the same structure and functionality when rewriting this code in C. |
options replace format comments java crossref symbols nobinary
say "give me the X and Y dimensions as two positive integers:"
parse ask xDim yDim
xPos = xDim % 2 -- integer divide to get close to the middle of the array
yPos = yDim % 2
arry = Rexx[xDim, yDim]
arry[xPos, yPos] = xDim / yDim -- make up a value...
say "arry["xPos","yPos"]:" arry[xPos, yPos]
return
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Can you help me rewrite this code in C# instead of REXX, keeping it the same logically? |
options replace format comments java crossref symbols nobinary
say "give me the X and Y dimensions as two positive integers:"
parse ask xDim yDim
xPos = xDim % 2 -- integer divide to get close to the middle of the array
yPos = yDim % 2
arry = Rexx[xDim, yDim]
arry[xPos, yPos] = xDim / yDim -- make up a value...
say "arry["xPos","yPos"]:" arry[xPos, yPos]
return
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Write the same code in C++ as shown below in REXX. |
options replace format comments java crossref symbols nobinary
say "give me the X and Y dimensions as two positive integers:"
parse ask xDim yDim
xPos = xDim % 2 -- integer divide to get close to the middle of the array
yPos = yDim % 2
arry = Rexx[xDim, yDim]
arry[xPos, yPos] = xDim / yDim -- make up a value...
say "arry["xPos","yPos"]:" arry[xPos, yPos]
return
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Transform the following REXX implementation into Java, maintaining the same output and logic. |
options replace format comments java crossref symbols nobinary
say "give me the X and Y dimensions as two positive integers:"
parse ask xDim yDim
xPos = xDim % 2 -- integer divide to get close to the middle of the array
yPos = yDim % 2
arry = Rexx[xDim, yDim]
arry[xPos, yPos] = xDim / yDim -- make up a value...
say "arry["xPos","yPos"]:" arry[xPos, yPos]
return
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Convert the following code from REXX to Python, ensuring the logic remains intact. |
options replace format comments java crossref symbols nobinary
say "give me the X and Y dimensions as two positive integers:"
parse ask xDim yDim
xPos = xDim % 2 -- integer divide to get close to the middle of the array
yPos = yDim % 2
arry = Rexx[xDim, yDim]
arry[xPos, yPos] = xDim / yDim -- make up a value...
say "arry["xPos","yPos"]:" arry[xPos, yPos]
return
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Write a version of this REXX function in VB with identical behavior. |
options replace format comments java crossref symbols nobinary
say "give me the X and Y dimensions as two positive integers:"
parse ask xDim yDim
xPos = xDim % 2 -- integer divide to get close to the middle of the array
yPos = yDim % 2
arry = Rexx[xDim, yDim]
arry[xPos, yPos] = xDim / yDim -- make up a value...
say "arry["xPos","yPos"]:" arry[xPos, yPos]
return
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Maintain the same structure and functionality when rewriting this code in Go. |
options replace format comments java crossref symbols nobinary
say "give me the X and Y dimensions as two positive integers:"
parse ask xDim yDim
xPos = xDim % 2 -- integer divide to get close to the middle of the array
yPos = yDim % 2
arry = Rexx[xDim, yDim]
arry[xPos, yPos] = xDim / yDim -- make up a value...
say "arry["xPos","yPos"]:" arry[xPos, yPos]
return
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Preserve the algorithm and functionality while converting the code from Ruby to C. | require "random"
first = gets.not_nil!.to_i32
second = gets.not_nil!.to_i32
arr = Array(Array(Int32)).new(first, Array(Int32).new second, 0)
random = Random.new
first = random.rand 0..(first - 1)
second = random.rand 0..(second - 1)
arr[first][second] = random.next_int
puts arr[first][second]
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Produce a language-to-language conversion: from Ruby to C#, same semantics. | require "random"
first = gets.not_nil!.to_i32
second = gets.not_nil!.to_i32
arr = Array(Array(Int32)).new(first, Array(Int32).new second, 0)
random = Random.new
first = random.rand 0..(first - 1)
second = random.rand 0..(second - 1)
arr[first][second] = random.next_int
puts arr[first][second]
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Generate an equivalent C++ version of this Ruby code. | require "random"
first = gets.not_nil!.to_i32
second = gets.not_nil!.to_i32
arr = Array(Array(Int32)).new(first, Array(Int32).new second, 0)
random = Random.new
first = random.rand 0..(first - 1)
second = random.rand 0..(second - 1)
arr[first][second] = random.next_int
puts arr[first][second]
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Transform the following Ruby implementation into Java, maintaining the same output and logic. | require "random"
first = gets.not_nil!.to_i32
second = gets.not_nil!.to_i32
arr = Array(Array(Int32)).new(first, Array(Int32).new second, 0)
random = Random.new
first = random.rand 0..(first - 1)
second = random.rand 0..(second - 1)
arr[first][second] = random.next_int
puts arr[first][second]
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Write a version of this Ruby function in Python with identical behavior. | require "random"
first = gets.not_nil!.to_i32
second = gets.not_nil!.to_i32
arr = Array(Array(Int32)).new(first, Array(Int32).new second, 0)
random = Random.new
first = random.rand 0..(first - 1)
second = random.rand 0..(second - 1)
arr[first][second] = random.next_int
puts arr[first][second]
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Generate an equivalent VB version of this Ruby code. | require "random"
first = gets.not_nil!.to_i32
second = gets.not_nil!.to_i32
arr = Array(Array(Int32)).new(first, Array(Int32).new second, 0)
random = Random.new
first = random.rand 0..(first - 1)
second = random.rand 0..(second - 1)
arr[first][second] = random.next_int
puts arr[first][second]
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Port the following code from Ruby to Go with equivalent syntax and logic. | require "random"
first = gets.not_nil!.to_i32
second = gets.not_nil!.to_i32
arr = Array(Array(Int32)).new(first, Array(Int32).new second, 0)
random = Random.new
first = random.rand 0..(first - 1)
second = random.rand 0..(second - 1)
arr[first][second] = random.next_int
puts arr[first][second]
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Convert this Scala block to C, preserving its control flow and logic. | fun main(args: Array<String>) {
val dim = arrayOf(10, 15)
val array = Array(dim[0], { IntArray(dim[1]) } )
array.forEachIndexed { i, it ->
it.indices.forEach { j ->
it[j] = 1 + i + j
}
}
array.forEach { println(it.asList()) }
}
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Produce a functionally identical C# code for the snippet given in Scala. | fun main(args: Array<String>) {
val dim = arrayOf(10, 15)
val array = Array(dim[0], { IntArray(dim[1]) } )
array.forEachIndexed { i, it ->
it.indices.forEach { j ->
it[j] = 1 + i + j
}
}
array.forEach { println(it.asList()) }
}
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Change the programming language of this snippet from Scala to C++ without modifying what it does. | fun main(args: Array<String>) {
val dim = arrayOf(10, 15)
val array = Array(dim[0], { IntArray(dim[1]) } )
array.forEachIndexed { i, it ->
it.indices.forEach { j ->
it[j] = 1 + i + j
}
}
array.forEach { println(it.asList()) }
}
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Generate an equivalent Java version of this Scala code. | fun main(args: Array<String>) {
val dim = arrayOf(10, 15)
val array = Array(dim[0], { IntArray(dim[1]) } )
array.forEachIndexed { i, it ->
it.indices.forEach { j ->
it[j] = 1 + i + j
}
}
array.forEach { println(it.asList()) }
}
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Change the programming language of this snippet from Scala to Python without modifying what it does. | fun main(args: Array<String>) {
val dim = arrayOf(10, 15)
val array = Array(dim[0], { IntArray(dim[1]) } )
array.forEachIndexed { i, it ->
it.indices.forEach { j ->
it[j] = 1 + i + j
}
}
array.forEach { println(it.asList()) }
}
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Write a version of this Scala function in VB with identical behavior. | fun main(args: Array<String>) {
val dim = arrayOf(10, 15)
val array = Array(dim[0], { IntArray(dim[1]) } )
array.forEachIndexed { i, it ->
it.indices.forEach { j ->
it[j] = 1 + i + j
}
}
array.forEach { println(it.asList()) }
}
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Rewrite the snippet below in Go so it works the same as the original Scala code. | fun main(args: Array<String>) {
val dim = arrayOf(10, 15)
val array = Array(dim[0], { IntArray(dim[1]) } )
array.forEachIndexed { i, it ->
it.indices.forEach { j ->
it[j] = 1 + i + j
}
}
array.forEach { println(it.asList()) }
}
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Convert this Tcl snippet to C and keep its semantics consistent. | puts "Enter width:"
set width [gets stdin]
puts "Enter height:"
set height [gets stdin]
for {set i 0} {$i < $width} {incr i} {
for {set j 0} {$j < $height} {incr j} {
set arr($i,$j) ""
}
}
set arr(0,0) "abc"
puts "Element (0/0): $arr(0,0)"
unset arr
| #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
|
Port the provided Tcl code into C# while preserving the original functionality. | puts "Enter width:"
set width [gets stdin]
puts "Enter height:"
set height [gets stdin]
for {set i 0} {$i < $width} {incr i} {
for {set j 0} {$j < $height} {incr j} {
set arr($i,$j) ""
}
}
set arr(0,0) "abc"
puts "Element (0/0): $arr(0,0)"
unset arr
| class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
|
Port the following code from Tcl to C++ with equivalent syntax and logic. | puts "Enter width:"
set width [gets stdin]
puts "Enter height:"
set height [gets stdin]
for {set i 0} {$i < $width} {incr i} {
for {set j 0} {$j < $height} {incr j} {
set arr($i,$j) ""
}
}
set arr(0,0) "abc"
puts "Element (0/0): $arr(0,0)"
unset arr
| #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
|
Change the following Tcl code into Java without altering its purpose. | puts "Enter width:"
set width [gets stdin]
puts "Enter height:"
set height [gets stdin]
for {set i 0} {$i < $width} {incr i} {
for {set j 0} {$j < $height} {incr j} {
set arr($i,$j) ""
}
}
set arr(0,0) "abc"
puts "Element (0/0): $arr(0,0)"
unset arr
| import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
|
Please provide an equivalent version of this Tcl code in Python. | puts "Enter width:"
set width [gets stdin]
puts "Enter height:"
set height [gets stdin]
for {set i 0} {$i < $width} {incr i} {
for {set j 0} {$j < $height} {incr j} {
set arr($i,$j) ""
}
}
set arr(0,0) "abc"
puts "Element (0/0): $arr(0,0)"
unset arr
| width = int(raw_input("Width of myarray: "))
height = int(raw_input("Height of Array: "))
myarray = [[0] * width for i in range(height)]
myarray[0][0] = 3.5
print (myarray[0][0])
|
Rewrite the snippet below in VB so it works the same as the original Tcl code. | puts "Enter width:"
set width [gets stdin]
puts "Enter height:"
set height [gets stdin]
for {set i 0} {$i < $width} {incr i} {
for {set j 0} {$j < $height} {incr j} {
set arr($i,$j) ""
}
}
set arr(0,0) "abc"
puts "Element (0/0): $arr(0,0)"
unset arr
| Module Program
Sub Main()
Console.WriteLine("Enter two space-delimited integers:")
Dim input = Console.ReadLine().Split()
Dim rows = Integer.Parse(input(0))
Dim cols = Integer.Parse(input(1))
Dim arr(rows - 1, cols - 1) As Integer
arr(0, 0) = 2
Console.WriteLine(arr(0, 0))
End Sub
End Module
|
Rewrite the snippet below in Go so it works the same as the original Tcl code. | puts "Enter width:"
set width [gets stdin]
puts "Enter height:"
set height [gets stdin]
for {set i 0} {$i < $width} {incr i} {
for {set j 0} {$j < $height} {incr j} {
set arr($i,$j) ""
}
}
set arr(0,0) "abc"
puts "Element (0/0): $arr(0,0)"
unset arr
| package main
import "fmt"
func main() {
var row, col int
fmt.Print("enter rows cols: ")
fmt.Scan(&row, &col)
a := make([][]int, row)
for i := range a {
a[i] = make([]int, col)
}
fmt.Println("a[0][0] =", a[0][0])
a[row-1][col-1] = 7
fmt.Printf("a[%d][%d] = %d\n", row-1, col-1, a[row-1][col-1])
a = nil
}
|
Rewrite this program in Rust while keeping its functionality equivalent to the C version. | #include <stdio.h>
int main(int argc, char **argv) {
int user1 = 0, user2 = 0;
printf("Enter two integers. Space delimited, please: ");
scanf("%d %d",&user1, &user2);
int array[user1][user2];
array[user1/2][user2/2] = user1 + user2;
printf("array[%d][%d] is %d\n",user1/2,user2/2,array[user1/2][user2/2]);
return 0;
}
| use std::env;
fn main() {
let mut args = env::args().skip(1).flat_map(|num| num.parse());
let rows = args.next().expect("Expected number of rows as first argument");
let cols = args.next().expect("Expected number of columns as second argument");
assert_ne!(rows, 0, "rows were zero");
assert_ne!(cols, 0, "cols were zero");
let mut v = vec![vec![0; cols]; rows];
v[0][0] = 1;
println!("{}", v[0][0]);
}
|
Produce a language-to-language conversion: from C++ to Rust, same semantics. | #include <iostream>
int main()
{
int dim1, dim2;
std::cin >> dim1 >> dim2;
double* array_data = new double[dim1*dim2];
double** array = new double*[dim1];
for (int i = 0; i < dim1; ++i)
array[i] = array_data + dim2*i;
array[0][0] = 3.5;
std::cout << array[0][0] << std::endl;
delete[] array;
delete[] array_data;
return 0;
}
| use std::env;
fn main() {
let mut args = env::args().skip(1).flat_map(|num| num.parse());
let rows = args.next().expect("Expected number of rows as first argument");
let cols = args.next().expect("Expected number of columns as second argument");
assert_ne!(rows, 0, "rows were zero");
assert_ne!(cols, 0, "cols were zero");
let mut v = vec![vec![0; cols]; rows];
v[0][0] = 1;
println!("{}", v[0][0]);
}
|
Generate an equivalent Rust version of this C# code. | class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter two integers. Space delimited please: ");
string s = Console.ReadLine();
int[,] myArray=new int[(int)s[0],(int)s[2]];
myArray[0, 0] = 2;
Console.WriteLine(myArray[0, 0]);
Console.ReadLine();
}
}
| use std::env;
fn main() {
let mut args = env::args().skip(1).flat_map(|num| num.parse());
let rows = args.next().expect("Expected number of rows as first argument");
let cols = args.next().expect("Expected number of columns as second argument");
assert_ne!(rows, 0, "rows were zero");
assert_ne!(cols, 0, "cols were zero");
let mut v = vec![vec![0; cols]; rows];
v[0][0] = 1;
println!("{}", v[0][0]);
}
|
Transform the following Java implementation into Rust, maintaining the same output and logic. | import java.util.Scanner;
public class twoDimArray {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int nbr1 = in.nextInt();
int nbr2 = in.nextInt();
double[][] array = new double[nbr1][nbr2];
array[0][0] = 42.0;
System.out.println("The number at place [0 0] is " + array[0][0]);
}
}
| use std::env;
fn main() {
let mut args = env::args().skip(1).flat_map(|num| num.parse());
let rows = args.next().expect("Expected number of rows as first argument");
let cols = args.next().expect("Expected number of columns as second argument");
assert_ne!(rows, 0, "rows were zero");
assert_ne!(cols, 0, "cols were zero");
let mut v = vec![vec![0; cols]; rows];
v[0][0] = 1;
println!("{}", v[0][0]);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.