Fortran study notes (1-3)

Source: Internet
Author: User
Tags arithmetic arithmetic operators constant numeric natural logarithm

The first high-level language was born in 1945, the German Chu translated his Z-4 computer design plan Calcul, a few months earlier than the first computer;
! The first high-level language to be achieved in the computer is the Shortcode, which was successfully developed by American Uyuni in 1952;
The first high-level language that is still popular today is the American computer scientist Backus Design, while really getting promoted to use,
And in 1956 the Fortran language was first implemented on IBM's computer.

! Representation and storage of numeric data: integer, real, plural! Representation and storage of non-numeric data: Character type, logic type


! Constants: Integer, real, complex, character, logical constant (. true. and. False.), symbol (parameter (identifier = constant,...) )


Variable: Declares the data type of the variable (first declared, then used)
Integer i,j,k
Real A, b
Complex m
Character* 8 C
Integer (2):: A=1,b


! Variable initialization:
Integer A
A=20
Or
Integer:: a=20
Or
Real A,b,c
Data a,b,c/1,2,3/
Real M,n,k
Data m,n,k/3*5/! The values are all 5.


! arithmetic operators, arithmetic expressions
Standard function, FORTRAN95 provides more than 130 standard functions
ABS (x); cos (x); sin (x); tan (x); ACOs (x); ASIN (x) ' Atan (x)! The argument unit of the trigonometric function is radians
Log (x)! Natural logarithm
LOG10 (x)! Common logarithm
ESP (x); sqrt (x); int (x)! Rounding to 0
MoD (x, y); Max (x1,x2,...); Min (x1,x2,...)
sign (x, y)! To find the absolute value of x multiplied by the Y symbol
Huge (x)!x The maximum value of the owning type
Tiny (x)!x the minimum value of the owning type
Len (s)! The length of the string s
sizeof (x)!x number of bytes stored
Nint (x)! Rounding the rounding
CHAR (n)! Converts the ASCII code n to the corresponding character
Ichar (c)! Converts the character C to the corresponding ASCII code


! Assignment Statements
! Match the data type to the left of the assignment number


! Input and OUTPUT statements
! Table control Output Input:
Print*,!* represents the output from the system implicitly specified output device, in accordance with the system implicitly defined by the format
read*,!* means input from the system implicitly specified input device on the system implied by the format
Read (*,*)! The first * indicates that the system implicitly specifies the input device, and the second * represents the table control input


! Formatted output input
Print statement label, output item
Statement label format (format description)


Write statement label, output item
Statement label format (format description)


Read statement designator, output item
Statement label format (format description)


! Format Description:
I-Edit: for integer data
F-Edit: Real data for fractional form
E-EDIT: Real data for exponential form
L-Edit: for logical data
A editor: for character data
X-Edit: Used to insert spaces between output items
Slash (/) Editor: for line wrapping


!end statement, stop statement, and pause statement


! Program Examples:
!1. Calculating the area of a triangle
Real X,y,z,c,s
Read *,x,y,z
C= (x+y+z)/2
S=sqrt (c* (c-x) * (c-y) * (c-z))
print*, "triangular area:", S
End
!2. Swap the values of two variables
Integer A, b
Read*,a,b
print*, "The values of A and B before swapping are:", "a=", A, "b=", b
T=a;a=b;b=t
print*, "After Exchange:", "a=", A, "b=", b
End

!3. Output a three-digit number and then output the square value of each bit

Integer A, b
Integer i,j,k,n
Read*,a,b
Read*,n
print*, "The values of A and B before swapping are:", "a=", A, "b=", b
T=a;a=b;b=t
print*, "After Exchange:", "a=", A, "b=", b
print*, "the original three-digit number is:", n
I=mod (n,10)
J=mod (n/10,10)
k=n/100
print*, "Square of single digits:", i**2
print*, "Square of 10 digits:", j**2
print*, "Square of the Hundred:", k**2
Print*,ia
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.