Tutorial for Fortran | Control Statements

in utopian-io •  7 years ago  (edited)


GitHub Repository:https://github.com/wavebitscientific/functional-fortran
Fortran (FORTRAN) is a general purpose, procedural, mandatory programming language, particularly suitable for numerical computation and scientific computing.

Fortran

The first version for the IBM 704, produced by IBM in 1954, was developed by John Backus and his team. Backus and his team published a report in November 1954 entitled "The IBM Mathematical FORmula TRANslating System: Fortran".

What Will I Learn?

  • I will try to give you information about the use of Fortran Programming Language. This series will proceed step by step. At the end of our project, we will have learned the Fortran Programming and Calculus Language. I will strive to give you a useful education.

Requirements

  • To develop and examine the concept of problem solving
  • Thinking and developing other things while solving problems
  • Force 2.0

Difficulty

  • Intermediate

Curriculum

| |

Control Statements

Control statements are one of the most important parts of the FORTRAN 90 programming language. Control statements extend computer programs beyond simply doing input / output and some mathematical calculations. Commands in a computer program are processed according to the order of writing from top to bottom.
Sometimes, however, the order in which these commands are processed may need to change. This provides control statements for changing the sequence.

IF Statements

The simplest form of control statements. If a certain condition is satisfied, the given commands (command1, command2, ..., commandN) are processed, and if it does, no action is taken. But the commands after the if command are processed. The general use of the Fortran 90 program is as follows;

if   (condition)  then
       condition1
       condition2
       .
       .
       .
       conditionN

end if

Now let me explain with an example;

Example 1 : We write the FORTRAN 90 program that finds the largest of the three numbers entered on the screen and prints it back to the screen.
Solution 1 ;
program thebiggest


implicit none

integer : : a , b , c , eb

print* , '' enter three numbers with spaces between them''

read* , a , b , c

tb=a

if (b>tb) then

      tb=b

end  if

if   (c>tb)   then

     tb=c

print* , ''the greatest number of entered numbers = , tb 

end program

Now you can use these codes as an example;

program thebiggest

implicit none

integer : : a , b , c , eb

print* , ''3 9 5''

read* , a , b , c

tb=a

if (b>tb) then

      tb=b

end  if

if   (c>tb)   then

     tb=c

print* , ''9''= , tb 

end program

If-Else Statements

Unlike the if statement described above, if the condition is true, then the command (s) after the 'then' statement (s) _1, if not true, will execute the command (s) _2 after the statement 'else'.

Use in FORTRAN 90 program;

If      (condition)     then

                     command( s )_1

else

                    command( s )_2

end if
  • Now let me explain with an example;
Example 2:We write a FORTRAN 90 program that finds out whether an exact number entered from the keyboard is single or double and prints "single" or "double" to the screen.
Solution 2 ;
program    ca1a

implicit     none

integer  :  :  number

print* , ''Enter a number=''

read* , number

if   (mod(number ,2)==0) then

       print*, ''double''

else

       print*, ''single''

end  if 

end program
  • Now let me explain with an example;
Example 3: I do not calculate the average when the visa and the final note do not enter on the screen with the keyboard, let's write a Fortran 90 program that prints the note average 'pass' or 'stay',
Solution 3 ;
program  ca1

implicit  none

integer : : v , f

real   :  : average

print*, '' visa note =''

read* , v

print* , '' final note =''

read* , F

ort= v* 0.4 + f* 0.6

print* , '' average note ='' ,  average

if    (average>=50)   then

         print* ''passed''

else

        print* ''stayed''

end if

end program
  • Now let's make an example of how the average of the final grades of the visa will be found;

Visa Note: 42 | Final Note: 69

program  ca1

implicit  none

integer : : v , f

real   :  : average

print*, '' 42 =''

read* , v

print* , '' 69 =''

read* , F

average = v* 0.4 + f* 0.6

print* , '' average note ='' ,  average

if    (58,200>=50)   then

         print* ''passed''

end if

end program

IF-ELSE IF Statements

This statement is used when there are more than two conditions in the program. Use in Fortran 90 program;

if   (condition)    then

                    command( s)_1

else     if    (condition_2)    then

                    command(s)_2

else    if      (condition_3)    then

                      command(s)_3

.....

else
 
                      command(s)_end

end if
  • If condition_1 is true, command (s) _1, condition _2 is true, then command (s) _2, .... will be processed, and if all conditions are false, command (s) after 'else'.

  • Now let me explain with an example;

Example 4: Let's write a forty-nine program that determines whether the exact number entered from the keyboard is positive, negative, or zero.
Solution 4;
program ca2a

implicit   none

integer  :  : number

Print*,  '' enter to number =''

read* , number

if     (sayi>0)   then

       print* , ''positive''

else   if(number<0)  then

      print* , ''negative''

else

            print*, ''zero''

end if

end program

Thus, we learned to do the most important part of the programming language, the calculation, the input-output. In the next lesson I will continue to describe other expressions.



Posted on Utopian.io - Rewarding Open Source Contributors

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

#tr

Please be mindful of country-specific tags. These tags are for articles written in that countries language or about that country.

Using irrelevant tags, especially popular tags, makes it hard to find good and relevant content. Please use only relevant tags when posting!

TIP: You can edit any tag but the first!

Thank You! ⚜

Your contribution cannot be approved because it does not follow the Utopian Rules.

  • The contribution cannot be approved, it shows only trivial steps to calculation with the if-statement.

  • Tutorials must be technical instructions that teach non-trivial aspects of an Open Source project.

  • basic programming concepts (variables, operators, loops, etc.) will not be accepted.

You can contact us on Discord.
[utopian-moderator]