answersLogoWhite

0

Here is a simple FORTRAN code to calculate the factorial of a given non-negative integer:

program factorial
    implicit none
    integer :: n, result

    print *, "Enter a non-negative integer:"
    read *, n

    result = 1
    if (n < 0) then
        print *, "Factorial is not defined for negative numbers."
    else
        do i = 1, n
            result = result * i
        end do
        print *, "Factorial of", n, "is", result
    end if
end program factorial

This program prompts the user for an integer, checks if it's non-negative, and then calculates the factorial using a loop.

User Avatar

AnswerBot

1mo ago

What else can I help you with?

Continue Learning about Engineering

How do you write a program on watfor77?

To write a program in Watfor77, you start by using a text editor to create a source code file with a .f extension. The program follows Fortran 77 syntax, which includes defining variables, writing subroutines, and using control structures like loops and conditionals. Once your code is written, you compile it using the Watfor77 compiler, which translates the Fortran code into an executable format. Finally, you run the compiled program to see the output.


Why learn Fortran?

Fortran was designed by, and for, people who wanted raw number-crunching speed. There's a great deal of legacy code written in Fortran, and the embarrassing (to snobs who prefer object-oriented languages) secret is that attempts to rewrite that code in a more "stylish" language result in programs that just don't run as fast.


Which command would you use to run a Fortran code?

Fortran is a programming language, which means you write a program in Fortran, and COMPILE it to an EXECUTABLE program. The compiler you use differs depending on which operating system platform you intend to run the program on. If you wish to run the program on a PC using Windows XP, you must first compile it using a specific Fortran-compiler for Windows XP. The result after compiling will be an executable file (with the file-ending .exe). To find a suitable compiler, check out download.com, for instance. Given that you know it is Fortran Code, we can assume that you do not have a compiled one, but just raw Frotran Source code. To compile it, you need a Fortan compiler suitable for both your operating system as well as the version of Fortran the code was written for. There is a free Fortran Compiler for Fortran77 from the GNU Project: For Windows: http://www.geocities.com/Athens/Olympus/5564/ For Unix: http://www.gnu.org/software/fortran/fortran.HTML The above is correct assuming your question is "Given the Fortran source code, how do I run it?" However if your question is "Given the Fortran executable (ProgName.exe) how do I run it?", the is that you run it like any other program. You either: 1 - Double-click on the file name OR 2 - Open a DOS window, go to the directory where the file is and type in the filename with or without the extension .exe OR 3 - You can select Start and Run and type in the filename. Like any "compilable" language it can be used to build an exe or a dll. But a dll MUST be called by another program to run, you can only run a .exe directly. ------------------ In addition the workflow for running a Fortran program on a *nix platform (such as Unix, Linux, or Mac OSx) would be as such: 1) Write given Fortran code with proper extension a) Fortran 77 - *.fb) Fortran 90 - *.f90c) Fortran 95 - *.f95 2) Compile using your compiler suite (showing examples for a few different cases) a) for gfortran as mentioned abovegfortran myfile.f90 -o myExecutableg77 myfile.f77 -o myExecutableb) for OpenMPImpif90 myfile.f90 -o myExecutablempif77 myfile.f77 -o myExecutablec) for Intel Fortranifort myfile.f90 -o myExecutable 3) To run the executable first make sure it is marked as executable, this can by going to the folder in which it was compiled then typing: ls -l You will then see the myExecutable file marked with permissions. Check to see if the executable permission is there. If it is not, you must change permissions to allow it to be executed. This is done by typing: chmod a+x myExecutable 4) Finally to actually run the code you simple add the execution prefix: ./myExecutable This will cause the file to run with output in the current terminal session. Note that if you terminate the terminal/ssh session, the code execution will halt. If you want to execute a large piece of code on lets say a remote computer (or a cluster for scientific computing) then you do the following step instead of 4 4*) To run the executable in backround and log terminal output (if you don't want to keep the terminal window open) you use the following command: nohup ./myExecutable &gt; terminalOuput.txt &amp; This will cause the executable to run in the background, it will the tell terminal not to hang up (nohup) if you close the window, and it will append the terminal output to the file terminalOutput.txt


What are the five examples computer language?

Machine code, assembly language, COBOL, FORTRAN and C. Machine code is the only language that is native to the machine. All others must be converted to machine code.


What was the earliest computer languages and were they Binary Code FORTRAN COBOL.?

The oldest computer language is machine code and all computer languages are binary encoded. It's unavoidable on binary machines.

Related Questions

What was the first high level language?

The first high-level programming language was called FORTRAN, which stands for &quot;Formula Translation.&quot; It was created in 1957 by John Backus (IBM) to help scientists and engineers write programs more easily.


How do you write a program on watfor77?

To write a program in Watfor77, you start by using a text editor to create a source code file with a .f extension. The program follows Fortran 77 syntax, which includes defining variables, writing subroutines, and using control structures like loops and conditionals. Once your code is written, you compile it using the Watfor77 compiler, which translates the Fortran code into an executable format. Finally, you run the compiled program to see the output.


If you have fortran 95 support can you compile fortran 90 code?

In most cases, yes. However this varies from compiler to compiler. Typically in my experiences, using gfortran and OpenMPI, F90 code will compile with very minor modification.


Why learn Fortran?

Fortran was designed by, and for, people who wanted raw number-crunching speed. There's a great deal of legacy code written in Fortran, and the embarrassing (to snobs who prefer object-oriented languages) secret is that attempts to rewrite that code in a more "stylish" language result in programs that just don't run as fast.


What are the three basic programming languages?

Machine Code, Assembler, &amp; High Level (FORTRAN, COBOL, C).


How can i plot graph in gnuplot-fortran progarm?

To plot a graph in a Gnuplot-Fortran program, you typically write your data to a file in a format that Gnuplot can read, such as plain text or CSV. Then, you can call Gnuplot from your Fortran code using system commands to execute a Gnuplot script or command that specifies how to display the data. For example, you might use SYSTEM('gnuplot -p -e &quot;plot \'data.txt\' using 1:2 with lines&quot;') to plot the data from the file data.txt. Ensure Gnuplot is installed and accessible in your system's PATH for this to work.


Is Fortran faster than C?

Fortran is not necessarily faster than C. The speed of a program depends on various factors such as the specific implementation, compiler optimizations, and the nature of the code itself. Both Fortran and C are high-performance languages commonly used in scientific computing, and the choice between them should be based on the specific requirements of the project.


Which command would you use to run a Fortran code?

Fortran is a programming language, which means you write a program in Fortran, and COMPILE it to an EXECUTABLE program. The compiler you use differs depending on which operating system platform you intend to run the program on. If you wish to run the program on a PC using Windows XP, you must first compile it using a specific Fortran-compiler for Windows XP. The result after compiling will be an executable file (with the file-ending .exe). To find a suitable compiler, check out download.com, for instance. Given that you know it is Fortran Code, we can assume that you do not have a compiled one, but just raw Frotran Source code. To compile it, you need a Fortan compiler suitable for both your operating system as well as the version of Fortran the code was written for. There is a free Fortran Compiler for Fortran77 from the GNU Project: For Windows: http://www.geocities.com/Athens/Olympus/5564/ For Unix: http://www.gnu.org/software/fortran/fortran.HTML The above is correct assuming your question is "Given the Fortran source code, how do I run it?" However if your question is "Given the Fortran executable (ProgName.exe) how do I run it?", the is that you run it like any other program. You either: 1 - Double-click on the file name OR 2 - Open a DOS window, go to the directory where the file is and type in the filename with or without the extension .exe OR 3 - You can select Start and Run and type in the filename. Like any "compilable" language it can be used to build an exe or a dll. But a dll MUST be called by another program to run, you can only run a .exe directly. ------------------ In addition the workflow for running a Fortran program on a *nix platform (such as Unix, Linux, or Mac OSx) would be as such: 1) Write given Fortran code with proper extension a) Fortran 77 - *.fb) Fortran 90 - *.f90c) Fortran 95 - *.f95 2) Compile using your compiler suite (showing examples for a few different cases) a) for gfortran as mentioned abovegfortran myfile.f90 -o myExecutableg77 myfile.f77 -o myExecutableb) for OpenMPImpif90 myfile.f90 -o myExecutablempif77 myfile.f77 -o myExecutablec) for Intel Fortranifort myfile.f90 -o myExecutable 3) To run the executable first make sure it is marked as executable, this can by going to the folder in which it was compiled then typing: ls -l You will then see the myExecutable file marked with permissions. Check to see if the executable permission is there. If it is not, you must change permissions to allow it to be executed. This is done by typing: chmod a+x myExecutable 4) Finally to actually run the code you simple add the execution prefix: ./myExecutable This will cause the file to run with output in the current terminal session. Note that if you terminate the terminal/ssh session, the code execution will halt. If you want to execute a large piece of code on lets say a remote computer (or a cluster for scientific computing) then you do the following step instead of 4 4*) To run the executable in backround and log terminal output (if you don't want to keep the terminal window open) you use the following command: nohup ./myExecutable &gt; terminalOuput.txt &amp; This will cause the executable to run in the background, it will the tell terminal not to hang up (nohup) if you close the window, and it will append the terminal output to the file terminalOutput.txt


What are the five examples computer language?

Machine code, assembly language, COBOL, FORTRAN and C. Machine code is the only language that is native to the machine. All others must be converted to machine code.


What was the earliest computer languages and were they Binary Code FORTRAN COBOL.?

The oldest computer language is machine code and all computer languages are binary encoded. It's unavoidable on binary machines.


What has the author R S Caswell written?

R S. Caswell has written: 'A Fortran code for calculation of Eigenvalues and Eigenfunctions in real potential wells'


Source code Thomas algorithm to solve trichagonal system of finite difference method?

Visit related link below for coding in C,Matlab, Fortran