112k views
2 votes
Goal: (1) Get first-hand coding experience with FORTRAN

(2) Develop self-learning capability
Edit your source code, test and debug, copy and paste into a notepad txt file and submit. The code may not look good after you paste it into the notepad, but hopefully it will look good again after it is copied from the txt file and pasted into the editor. Try it yourself before you submit the file.
This is what you need to do:
There are two functions: area and fac.
The area function takes two real number parameters: length and width. It returns length*width.
The fac function is a recursive function. (Read the second reading). It calculate the n! as n*(n-1)*(n-2)*...*3*2*1. By definition, 0! = 1.
Your "main" subprogram, ask the user to enter the length and width of a rectangle, then display "The area is " and display the area using the area( ) function. After that, ask the user to enter a non-negative integer n, display n! by calling the fac function.
You will get a B if the area function works. You will get an A if both function work. You will get 90 points (Marginal A) if you do the fac function but not the area function. A program that is not fully functional may still get credit or even most of the credit as long as the code is good.

User Fiodor
by
8.4k points

1 Answer

4 votes

Final answer:

A FORTRAN program is required to calculate the area of a rectangle and the factorial of a number, using functions that implement basic geometric and mathematical principles including recursion. The program must be user-interactive, allowing input and displaying results for area and factorial computations. Formatting issues are to be considered when the code is transferred to and from a plain text format.

Step-by-step explanation:

Introduction to FORTRAN Coding

To fulfill the assignment, a student is required to create source code in FORTRAN that contains two functions: one for calculating the area of a rectangle and another for computing the factorial of a number (fac function). The area function multiplies the length by the width to find the area of a rectangle, reflecting the basic geometric principle that the area is equal to the product of the two dimensions. The fac function is a recursive function that calculates the factorial of a number by multiplying it by each natural number less than itself down to one, with the base case where 0! equals one.

The student's main program will prompt the user to input the dimensions of a rectangle and then display the area. Additionally, the user will be prompted to input a non-negative integer for the factorial calculation. Testing and debugging are essential parts of developing a functional program. After editing and confirming the code works within a FORTRAN editor, it will be converted into a plain text format for submission, with the understanding that formatting may change and must be verified upon pasting the code back into the editor.

Applying Mathematics in Coding

In coding, mathematical functions can be implemented and tested, such as squaring numbers or finding roots, to ensure a deeper understanding of the principles involved. This practice can be particularly helpful when creating functions like the fac function, which requires an understanding of mathematical principles such as recursion and factorial calculation. When working with geometry and shapes, it's important to remember that units are significant, and the result should appropriately reflect this, such as calculating areas in square meters.

User Jacek Sztandera
by
8.4k points