forked from root/public
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.
…
|
||
---|---|---|
.. | ||
README.md |
README.md
matrix_multiplication
Instructions
-
Define a
struct
namedMatrix
as a tuple of two tuples. The nested tuple will contain twoi32
. -
Create a function named
multiply
that receives aMatrix
and ani32
and returns theMatrix
with each number multiplied by the second argument.
pub fn multiply(m: Matrix, multiplier: 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::*;
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))
$