0% found this document useful (0 votes)
10 views3 pages

FORTRAN Assignment Codes

This document provides a guide for a FORTRAN programming assignment, including code examples for input/output, loops, decision making, arrays, arithmetic operations, and subroutines. Each section contains a sample program demonstrating the respective concept. The examples are designed to help students understand basic FORTRAN programming structures and syntax.

Uploaded by

Kunal chan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

FORTRAN Assignment Codes

This document provides a guide for a FORTRAN programming assignment, including code examples for input/output, loops, decision making, arrays, arithmetic operations, and subroutines. Each section contains a sample program demonstrating the respective concept. The examples are designed to help students understand basic FORTRAN programming structures and syntax.

Uploaded by

Kunal chan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

FORTRAN Programming Assignment Guide

This document contains FORTRAN code examples for the assignment.

A. Input and Output

! Simple Input and Output Example


PROGRAM IOExample
IMPLICIT NONE
INTEGER :: age

PRINT *, 'Enter your age:'


READ *, age
PRINT *, 'Your age is:', age

END PROGRAM IOExample

B. Loops

! Loop Example (Printing numbers from 1 to 10)


PROGRAM LoopExample
IMPLICIT NONE
INTEGER :: i

DO i = 1, 10
PRINT *, 'Number:', i
END DO

END PROGRAM LoopExample

C. Decisions

! Decision Making Example (If-Else Statement)


PROGRAM DecisionExample
IMPLICIT NONE
INTEGER :: number

PRINT *, 'Enter a number:'


READ *, number

IF (number > 0) THEN


PRINT *, 'The number is positive.'
ELSE IF (number < 0) THEN
PRINT *, 'The number is negative.'
ELSE
PRINT *, 'The number is zero.'
END IF

END PROGRAM DecisionExample

D. Arrays

! Array Example (Storing and Printing Values)


PROGRAM ArrayExample
IMPLICIT NONE
INTEGER, DIMENSION(5) :: numbers
INTEGER :: i

PRINT *, 'Enter 5 numbers:'


DO i = 1, 5
READ *, numbers(i)
END DO

PRINT *, 'The numbers you entered are:'


PRINT *, numbers

END PROGRAM ArrayExample

E. Arithmetic/Assignment Statements

! Arithmetic Operations Example


PROGRAM ArithmeticExample
IMPLICIT NONE
REAL :: a, b, sum, difference, product, quotient

PRINT *, 'Enter two numbers:'


READ *, a, b

sum = a + b
difference = a - b
product = a * b
quotient = a / b

PRINT *, 'Sum:', sum


PRINT *, 'Difference:', difference
PRINT *, 'Product:', product
PRINT *, 'Quotient:', quotient

END PROGRAM ArithmeticExample

F. Subroutines

! Subroutine Example (Calculating Square)


PROGRAM SubroutineExample
IMPLICIT NONE

REAL :: number, result

PRINT *, 'Enter a number:'


READ *, number

CALL Square(number, result)


PRINT *, 'The square of the number is:', result

CONTAINS

SUBROUTINE Square(x, y)
REAL, INTENT(IN) :: x
REAL, INTENT(OUT) :: y
y = x * x
END SUBROUTINE Square

END PROGRAM SubroutineExample

You might also like