0% found this document useful (0 votes)
5 views

FORTRAN_Assignment_Guide

This document provides a comprehensive guide for installing GFortran and executing FORTRAN programs for the CSC 280.1 assignment. It includes detailed instructions for Windows, Linux, and Mac users, as well as examples of basic programming concepts such as input/output, loops, conditional statements, arrays, arithmetic operations, and subroutines. Additionally, it offers guidance on capturing and submitting output screenshots from the terminal.

Uploaded by

Kunal chan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

FORTRAN_Assignment_Guide

This document provides a comprehensive guide for installing GFortran and executing FORTRAN programs for the CSC 280.1 assignment. It includes detailed instructions for Windows, Linux, and Mac users, as well as examples of basic programming concepts such as input/output, loops, conditional statements, arrays, arithmetic operations, and subroutines. Additionally, it offers guidance on capturing and submitting output screenshots from the terminal.

Uploaded by

Kunal chan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

FORTRAN Programming Assignment Guide

This document provides step-by-step instructions on how to install GFortran, write, compile,
and run FORTRAN programs for the CSC 280.1 assignment.

1. Installing GFortran
GFortran can be installed based on your operating system:

For Windows:
1. Download MinGW-w64 from https://www.mingw-w64.org/downloads/
2. Install it and ensure Fortran is selected.
3. Add C:\mingw-w64\bin to your system's Environment Variables.

For Linux (Ubuntu/Debian):


1. Open a terminal and run:
sudo apt update
sudo apt install gfortran

For Mac:
1. Install Homebrew (if not installed):
/bin/bash -c "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. Install GFortran with:
brew install gcc

2. Writing and Running FORTRAN Programs


1. Open a text editor (Notepad, VS Code, or Sublime Text).
2. Write a FORTRAN program and save it with a .f90 extension.
3. Open a terminal and navigate to the folder where your file is saved.
4. Compile the program using:
gfortran program.f90 -o program
5. Run the program:
./program (Linux/Mac) or program.exe (Windows)

3. Assignment Questions and Solutions


A. Input and Output

Input allows users to enter data, while output displays results.


Example program:
------------------------
PROGRAM InputOutput
IMPLICIT NONE
INTEGER :: age
PRINT *, "Enter your age: "
READ *, age
PRINT *, "You are ", age, " years old."
END PROGRAM InputOutput

B. Loops

Loops repeat a block of code multiple times.


Example DO loop:
------------------------
PROGRAM LoopExample
IMPLICIT NONE
INTEGER :: i
DO i = 1, 5
PRINT *, "Iteration: ", i
END DO
END PROGRAM LoopExample

C. Decisions (Conditional Statements)

Decisions allow conditional execution of statements.


Example IF statement:
------------------------
PROGRAM DecisionExample
IMPLICIT NONE
INTEGER :: num
PRINT *, "Enter a number: "
READ *, num
IF (num > 0) THEN
PRINT *, "The number is positive."
ELSE IF (num < 0) THEN
PRINT *, "The number is negative."
ELSE
PRINT *, "The number is zero."
END IF
END PROGRAM DecisionExample

D. Arrays

Arrays store multiple values in a single variable.


Example:
------------------------
PROGRAM ArrayExample
IMPLICIT NONE
INTEGER, DIMENSION(5) :: numbers
INTEGER :: i
numbers = (/10, 20, 30, 40, 50/)
PRINT *, "Array elements:"
DO i = 1, 5
PRINT *, numbers(i)
END DO
END PROGRAM ArrayExample

E. Arithmetic/Assignment Statements

Arithmetic statements perform calculations.


Example:
------------------------
PROGRAM ArithmeticExample
IMPLICIT NONE
INTEGER :: a, b, sum
PRINT *, "Enter two numbers: "
READ *, a, b
sum = a + b
PRINT *, "Sum: ", sum
END PROGRAM ArithmeticExample

F. Subroutines

Subroutines are reusable blocks of code.


Example:
------------------------
PROGRAM SubroutineExample
IMPLICIT NONE
CALL Greet()
CONTAINS
SUBROUTINE Greet()
PRINT *, "Hello from the subroutine!"
END SUBROUTINE Greet
END PROGRAM SubroutineExample

4. Capturing Output Screenshots


After running your programs, take a screenshot of the terminal output:
- Windows: Press 'Windows + Shift + S' to capture the screen.
- Mac: Press 'Command + Shift + 4' to take a screenshot.
- Linux: Use 'Print Screen' or the screenshot tool.
Save the images and include them in your assignment submission.

You might also like