Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fmt;
- fn transpose(matrixces: Matrix) -> (Matrix) {
- let Matrix(f1, f2, f3, f4) = matrixces;
- Matrix(f1, f3, f2, f4)
- }
- #[derive(Debug)]
- struct Matrix(f32, f32, f32, f32);
- impl fmt::Display for Matrix {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "({} {})\n({} {})", self.0, self.1, self.2, self.3)
- }
- }
- fn main() {
- let matrix = Matrix(1.1, 1.2, 2.1, 2.2);
- println!("Matrix:\n{}", matrix);
- println!("Transpose: \n{}", transpose(matrix));
- }
Add Comment
Please, Sign In to add comment