ScrapExplorer - matrix.f90

Home / misc / fortran Lines: 1 | Size: 1767 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1! SPDX-License-Identifier: GPL-3.0 2! matrix 3! 4! matrix.f90 5! 6! COPYRIGHT NOTICE 7! Copyright (C) 2024-2025 0x4248 and contributors 8! This program is free software: you can redistribute it and/or modify 9! it under the terms of the GNU General Public License as published by 10! the Free Software Foundation, either version 3 of the License, or 11! (at your option) any later version. 12! 13! Redistribution and use in source and binary forms, with or without 14! modification, are permitted provided that the license is not changed. 15 16 17program matrix 18 implicit none 19 20 ! Declare variables 21 ! C = result 22 integer, parameter :: n = 3 23 real :: a(n, n), b(n, n), c(n, n) 24 integer :: i, j 25 26 ! Initialize matrices A and B 27 do i = 1, n 28 do j = 1, n 29 a(i, j) = real(i + j) 30 b(i, j) = real(i - j) 31 end do 32 end do 33 34 ! Print matrices A and B 35 print *, 'Matrix A:' 36 do i = 1, n 37 print '(3F5.1)', (a(i, j), j = 1, n) 38 end do 39 40 print *, '' 41 42 print *, 'Matrix B:' 43 do i = 1, n 44 print '(3F5.1)', (b(i, j), j = 1, n) 45 end do 46 47 print *, '' 48 49 50 ! Perform matrix operations 51 ! Addition 52 c = a + b 53 54 print *, 'Matrix C = A + B:' 55 do i = 1, n 56 print '(3F5.1)', (c(i, j), j = 1, n) 57 end do 58 59 print *, '' 60 61 ! Subtraction 62 c = a - b 63 64 print *, 'Matrix C = A - B:' 65 do i = 1, n 66 print '(3F5.1)', (c(i, j), j = 1, n) 67 end do 68 69 print *, '' 70 71 ! Multiplication 72 c = a * b 73 74 print *, 'Matrix C = A * B:' 75 do i = 1, n 76 print '(3F5.1)', (c(i, j), j = 1, n) 77 end do 78 79 print *, '' 80 81 ! Division 82 c = a / b 83 84 print *, 'Matrix C = A / B:' 85 do i = 1, n 86 print '(3F5.1)', (c(i, j), j = 1, n) 87 end do 88 89end program matrix 90
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.