You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.6 KiB

matrix_multiplication

Instructions

  • Define a struct named Matrix as a tuple of 2 tuples. The nested tuple will contain 2 i32s.

  • Create a function named multiply that receives a Matrix and an i32 and returns the Matrix with each number multiplied by the second argument.

pub fn multiply(m: Matrix, val: i32) -> Matrix {
}

Matrix must implement Debug, PartialEq and Eq. You can use derive.

Remember that you are defining a library, so any element that can be called from an external crate must be made public.

Usage

Here is a possible program to test your function

use matrix_multiplication::multiply;
use matrix_multiplication::Matrix;

fn main() {
    let matrix = Matrix((1, 3), (4, 5));
    println!("Original matrix {:?}", matrix);
    println!("Matrix after multiply {:?}", multiply(matrix, 3));
}

And its output:

$ cargo run
Original matrix Matrix ((1, 3), (4, 5))
Matrix after multiply ((3, 9), (12, 15))
$

Notions