Logo

Programming-Idioms

History of Idiom 26 > diff from v37 to v38

Edit summary for version 38 by Aquamo:
[Rust] change to use floating point numbers

Version 37

2018-05-09, 01:34:05

Version 38

2018-05-09, 01:38:57

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Illustration

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

Illustration
Code
fn main() {
  let a: [[i32; 4]; 4] = [[ 0,  1,  2,  3],
                          [ 4,  5,  6,  7],
                          [ 8,  9, 10, 11],
                          [12, 13, 14, 15]];

  assert_eq!(a[0][0], 0);
  assert_eq!(a[0][3], 3);
  assert_eq!(a[3][0], 12);

  println!("the value at 2,2 should be 10, {}", a[2][2]);
}
Code
fn main() {
  let a: [[f64; 4]; 4] = [[ 0.0,  1.0,  2.0,  3.0],
                          [ 4.0,  5.0,  6.0,  7.0],
                          [ 8.0,  9.0, 10.0, 11.0],
                          [12.0, 13.0, 14.0, 15.0]];

  assert_eq!(a[0][0], 0.0);
  assert_eq!(a[0][3], 3.0);
  assert_eq!(a[3][0], 12.0);

  println!("the value at 2,2 should be 10.0, {}", a[2][2]);
}