Sunteți pe pagina 1din 11

fortran by rege .

txt
PROGRAM CALCULATE_area_of_a_circle
REAL R,A
WRITE (*,*) "INPUT THE VALUE OF THE RADIUS"
READ (*,*) R
PI=3.142
A=PI*(R**2)
WRITE (*,*) 'THE AREA IS',A
END
________________________________________________________________________________
__________
________________________________________________________________________________
__________
program area_0f_circle_area_of_cylinder
real:: AOC,AOCY,pi,radius,height
pi=3.142
write(*,*)'input value of radius and height'
read(*,*)radius,height
AOC=pi*(radius**2)
AOCY=2*pi*radius*height
write(*,*)'AOC is',aoc
write(*,*)'AOC int is',int(aoc)
write(*,*)'AOC nint is',nint(aoc)
write(*,*)'AOC ifix is',ifix(aoc)
write(*,*)'AOCY is',aocy
end
________________________________________________________________________________
__________
________________________________________________________________________________
__________
PROGRAM CALCULATE_AREA_OF_SOLIDS
IMPLICIT NONE
REAL, PARAMETER :: PI = 3.14159
REAL ASPHERE, ACIRCLE, ACYLINDER,VOLSPHERE,VOLCYLINDER
INTEGER r,HEIGHT
WRITE (*,*) 'INPUT RADIUS'
READ (*,*) r
WRITE (*,*) 'INPUT HEIGHT'
READ (*,*) HEIGHT
!RAD SIGNIFIES THE RADIUS WHILE H IMPLIES HEIGHT
ASPHERE=4*PI*(r**2)
ACIRCLE=PI*(r**2)
ACYLINDER=2*PI*r*HEIGHT
VOLSPHERE = 4*PI*(r**3)/3
VOLCYLINDER = PI*(r**2)*HEIGHT
!FORMULAR FOR THE VARIOUS SOLIDS
WRITE(*,*) 'AREA OF SPHERE=', ASPHERE
WRITE(*,*) 'AREA OF CIRCLE=', ACIRCLE
WRITE(*,*) 'AREA OF CYLINDER=', ACYLINDER
WRITE(*,*) 'VOLUME OF SPHERE=', VOLSPHERE
WRITE(*,*) 'VOLUME OF CYLINDER=', VOLCYLINDER
END
________________________________________________________________________________
__________
________________________________________________________________________________
__________
PROGRAM CALCULATE_mean_of_five_numbers
IMPLICIT NONE
INTEGER:: A,B,C,D,E
REAL:: MEAN, SUM
WRITE(*,*)'INPUT NUMBERS'
READ (*,*) A,B,C,D,E
Page 1

fortran by rege .txt


SUM = A+B+C+D+E
MEAN= SUM/5.
WRITE (*,*)"SUM=", SUM
WRITE (*,*)'MEAN=', MEAN
END CALCULATE_MEAN

________________________________________________________________________________
__________
________________________________________________________________________________
__________
PROGRAM sum
!sum of five numbers
REAL :: X(5),Y
WRITE(*,*) 'INPUT THE FIVE VALUES'
READ (*,*) X
Y = 0
DO I = 1,5
Y = Y + X(I)
END DO
WRITE (*,*) Y
END
________________________________________________________________________________
__________
________________________________________________________________________________
__________
program mean_of_five_numbers
implicit none
integer i
real::mean,sum,a(5)
write(*,*)'input the five values'
read(*,*)a
sum = 0
do i = 1,5
sum = sum + a(i)
end do
mean = sum/5
write(*,*)'sum is',sum
write(*,*)'mean is',mean
end
________________________________________________________________________________
__________
________________________________________________________________________________
__________
program sum_xy
real::x(5),y(5),xy(5),sumxy
write(*,*)'input values for x'
read(*,*)x
write(*,*)'input values for y'
read(*,*)y
sumxy=0
do i=1,5
xy(i)=x(i)*y(i)
sumxy=sumxy+xy(i)
write(*,*)'xy is',xy(i)
end do
Page 2

fortran by rege .txt


write(*,*)'sum of the product of x and y is',sumxy
end program
________________________________________________________________________________
__________
________________________________________________________________________________
__________
program quad_eqn
real::a,b,c,d1,d2,z1,z2
write(*,*)'input coefficient value for a'
read(*,*)a
write(*,*)'input coefficient value for b'
read(*,*)b
write(*,*)'input coefficient value for c'
read(*,*)c
if ((b**2)<(4*a*c))then
WRITE (*,*) ' COMPLEX ROOTS exist '
x = (b**2)-(4*a*c)
y = x/(-1)
d1 = (-b/(2*a))
d2 = ((y**0.5)/(2*a))
write(*,*) 'x1=',d1,'+',d2,'j'
write(*,*) 'x2=',d1,'-',d2,'j'
else if ((b**2)==(4*a*c))then
WRITE (*,*) 'ONE REPEATED ROOT exist'
z1 = (-b+((b**2-(4*a*c))**0.5))/(2*a)
z2 = (-b-((b**2-(4*a*c))**0.5))/(2*a)
write(*,*) 'x1=',z1
write(*,*) 'x2=',z2
else if ((b**2)>(4*a*c))then
WRITE (*,*) 'TWO REAL ROOTS EXIST'
z1 = (-b+((b**2-(4*a*c))**0.5))/(2*a)
z2 = (-b-((b**2-(4*a*c))**0.5))/(2*a)
write(*,*) 'x1=',z1
write(*,*) 'x2=',z2
end if
end program
________________________________________________________________________________
__________
________________________________________________________________________________
__________
program mean_of_numbers____open_file
implicit none
integer i
real::mean,sum,a(5)
open(10,file='input.txt')
open(11,file='result.txt')
read(10,*)a
sum = 0
do i = 1,5
sum = sum + a(i)
end do
mean = sum/5
write(11,*)'sum is',sum
write(11,*)'mean is',mean
Page 3

fortran by rege .txt


close(10)
close(11)
end
!
!
!
!
!

the first time you run the program it will give an error
but in that process it will create the input and result text file
so after the first run, you open the input file and put in your values
save and close the file then re-run the program
then check the result file

________________________________________________________________________________
__________
________________________________________________________________________________
__________
program areas
! this program is calculating the normal area of circle,sphere and cylinder
! but the aim of this program is to put them in order using the 'format'
function
real::aoc,aos,aocy,rad,height
real,parameter::pi=3.142
character(len=20)::areacircle,areasphere,areacylinder,subject,values
write(*,*)'input rad'
read(*,*)rad
write(*,*)'input height'
read(*,*)height
aoc=pi*(rad**2)
aos=4*pi*(rad**2)
aocy=2*pi*rad*height
areacircle='area circle'
areasphere='area sphere'
areacylinder='area cylinder'
subject='subject'
values='answer'
write(*,100)'s/n',subject,values
write(*,200)'1',areacircle,aoc
write(*,200)'2',areasphere,aos
write(*,200)'3',areacylinder,aocy
100 format(a3,2x,a10,5x,a10)
200 format(a3,2x,a10,2x,f11.5)
end
________________________________________________________________________________
__________
________________________________________________________________________________
__________
PROGRAM AREA_AND_VOLUME_OF_SHAPES
IMPLICIT NONE
REAL::Radius, Height
REAL::Area_Circle, Area_Sphere, Area_Cylinder, Volume_Sphere, Volume_Cylinder
CHARACTER (len=20):: Area_of_circle, Area_of_sphere, Area_of_cylinder,
Volume_of_sphere, Volume_of_cylinder
CHARACTER (len=20):: Subject
REAL, PARAMETER::Pi=3.142
Area_of_circle = 'Area of circle'
Area_of_sphere = 'Area of sphere'
Area_of_cylinder = 'Area of cylinder'
Volume_of_sphere = 'Volume of sphere'
Volume_of_cylinder = 'Volume of cylinder'
Subject = 'Subject'
WRITE (*,*) 'Input value for Radius in meters'
Page 4

fortran by rege .txt


READ (*,*) Radius
WRITE (*,*) 'Input value for Height in meters'
READ (*,*) Height
WRITE (*,21) 'S/N', Subject, 'Value'
Area_Circle = Pi * Radius**2
WRITE (*,20) '1.', Area_of_circle, Area_Circle, 'm^2'
Area_Sphere = 4 * PI * Radius**2
WRITE (*,20) '2.', Area_of_sphere, Area_Sphere, 'm^2'
Area_Cylinder = 2 * PI * Radius * (Radius + Height)
WRITE (*,20) '3.', Area_of_cylinder, Area_Cylinder, 'm^2'
Volume_Sphere = (4 * PI * Radius**3) / 3
WRITE (*,20) '4.', Volume_of_sphere, Volume_Sphere, 'm^3'
Volume_Cylinder = PI * Radius**2 * Height
WRITE (*,20) '5.', Volume_of_cylinder, Volume_Cylinder, 'm^3'
21 format (a3, 5x, a21, 5x, a10)
20 format (a3, 5x, a21, 5x, f11.3, a3)
END AREA_AND_VOLUME_OF_SHAPES
________________________________________________________________________________
__________
________________________________________________________________________________
__________
program sumtwo
implicit none
integer::i,y(20),sum
sum=0
do i=1,20
y(i)=2**i
sum=sum+y(i)
write(*,100) '2^',i,y(i)
end do
write(*,*)'
-------------'
write(*,101)'sum >',sum
write(*,*)'
-------------'
100 format(a3,i2,2x,i8)
101 format(a5,2x,i10)
end sumtwo
________________________________________________________________________________
__________
________________________________________________________________________________
__________

program names_char
!this program is designed just to read five names and surnames
!and five scores (they had in a test) from three different text file
!and paste them on the screen
real,dimension(5)::testscore
character(len=10) :: fn,sn,score
character(len=10),dimension(5)::firstname,surname
!the first name text file
open(14,file='firstname.txt')
!the surname text file
open(15,file='surname.txt')
!the test score text file
open(16,file='testscore.txt')
read(14,*)firstname
Page 5

fortran by rege .txt


read(15,*)surname
read(16,*)testscore
fn = 'first name'
sn = 'surname'
score = 'testscore'
write(*,100) fn,sn,score
do i = 1,5
write(*,200) firstname(i),surname(i),testscore(i)
end do
100 format(a10,2x,a10,2x,a10)
200 format(a10,2x,a10,2x,f11.2)
close(14)
end
________________________________________________________________________________
__________
________________________________________________________________________________
__________

program scores
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! To include: Grades of Students
!!!!
!!!! To include: How many students with A's, B's, C's, D's & F's !!!!
!!!! To include: Output to a file
!!!!
!!!! USE IF STATEMENT, DO-LOOP,................................. !!!!
!!!!
!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!declaration of header for output
integer :: Aa,Bb,Cc,Dd,Ff
character(len=15)
::title_surname='SURNAME',title_firstname='FIRSTNAME',title_test1='TEST1'&
,title_test2='TEST2',title_exam='EXAM',title_total='TOTAL',title_grader='GRADES'
integer ::nstudents=46 ! number of students in the class
integer:: icounter
! counter for do-loop
!declaration of array for surname, firstname and scores of students that took
PET526-Petroleum Economics
character(len=20),dimension(46) ::surname, firstname, grades
integer, dimension(46) ::test1, test2, exam, total_score
! open statement to read file that holds the data
open(10,file='surname.txt')
open(11,file='firstname.txt')
open(12,file='test1.txt')
open(13,file='test2.txt')
open(14,file='exam.txt')
open(15,file='result.txt')
read(10,*) surname
!read(10,*) (surname(icounter),icounter=1,nstudents)
do icounter=1,nstudents !explicit do loop
read(11,*)firstname(icounter)
end do
!read(11,*)(firstname(icounter),icounter=1,nstudents)
read(12,*)(test1(icounter),icounter=1,nstudents)!implied do loop
read(13,*)(test2(icounter),icounter=1,nstudents)
read(14,*)(exam(icounter),icounter=1,nstudents)
Page 6

fortran by rege .txt


close(10)
close(11)
close(12)
close(13)
close(14)
! compute total sccore, the summation of test1 test2 and exam scores
do icounter=1,nstudents
total_score(icounter)=test1(icounter)+test2(icounter)+exam(icounter)
end do
Aa
Bb
Cc
Dd
Ff

=
=
=
=
=

0
0
0
0
0

Do icounter= 1, nstudents
if (total_score(icounter) >=70) then
grades(icounter)="A"
Aa = Aa + 1
elseif (total_score(icounter) >=60 .and. total_score(icounter) <70) then
grades(icounter)="B"
Bb = Bb + 1
elseif (total_score(icounter) >=50 .and. total_score(icounter) <60) then
grades(icounter)="C"
Cc = Cc + 1
elseif (total_score(icounter) >=45 .and. total_score(icounter) <50) then
grades(icounter)="D"
Dd = Dd + 1
elseif (total_score(icounter)<45) then
grades(icounter)="F"
Ff = Ff + 1
end if
end do

! output of header
write(15,100)
title_surname,title_firstname,title_test1,title_test2,title_exam,title_total,tit
le_grader
100 format(a10,12x,a10,10x,a5,3x,a5,3x,a5,1x,a5,1x,a5)

!output of surname, firstname, test1, test2, exam and total score with the aid
of explicit do-loop
do icounter=1,nstudents
write(15,200)surname(icounter), firstname(icounter),test1(icounter)&
, test2(icounter), exam(icounter), total_score(icounter),grades(icounter)
200 format(a20,2x,a20,i4,3x,i4,3x,i4,3x,i4,4x,2a)
end do
write(15,*)
write(15,*)
write(15,*)
write(15,*)
write(15,*)
close(15)

'A
'B
'C
'D
'F

=',Aa
=',Bb
=',Cc
=',Dd
=',Ff

end program scores


Page 7

fortran by rege .txt


________________________________________________________________________________
__________
________________________________________________________________________________
__________
!how function works
!these program is to find the average of three diferent sets of data
program function_sub
real h(4),w(4),a(4),r1,r2,r3
!creating the sets of data
write(*,*) 'input data 1'
read(*,*)h
write(*,*) 'input data 2'
read(*,*)w
write(*,*) 'input data 3'
read(*,*)a
!calling the function
!then using the function to compute the three sets of data
r1 = pro(h)
r2 = pro(w)
r3 = pro(a)
write(*,*) 'average of data 1 =',r1
write(*,*) 'average of data 2 =',r2
write(*,*) 'average of data 3 =',r3
end program function_sub
!the function to compute average of any data of four values
function pro(x)
real x(4),sum,pro
integer n,i
n = 4
sum = 0
do i = 1,n
sum = sum + x(i)
end do
pro = sum/n
return
end function

________________________________________________________________________________
__________
________________________________________________________________________________
__________
!how sub-routine works
!these program is to find the average of three diferent sets of data
program sub_routine
real x(4)
!creating data 1
write(*,*) 'input data 1'
read(*,*)x
Page 8

fortran by rege .txt


!computing data 1
call pro(x,y)
write(*,*)'average =', y
!creating data 2
write(*,*) 'input data 2'
read(*,*)x
!computing data 2
call pro(x,y)
write(*,*)'average =', y
!creating data 3
write(*,*) 'input data 3'
read(*,*)x
!computing data 3
call pro(x,y)
write(*,*)'average =', y
end program sub_routine
!the subroutine to compute average of the data of four values
subroutine pro(x,y)
real x(4),sum,y
integer n,i
n = 4
sum = 0
do i = 1,n
sum = sum + x(i)
end do
y = sum/n
end subroutine pro
________________________________________________________________________________
__________
________________________________________________________________________________
__________
!class work on function
!CLASS EXPLAINATION

17-02-2014

PROGRAM HEIGHTANDWEIGHT
REAL, DIMENSION(10)::HEIGHT, WEIGHT
REAL:: AVEHEIGHT, AVEWEIGHT
INTEGER:: I=10
OPEN(10,FILE='HEIGHT.TXT')
OPEN(11,FILE='WEIGHT.TXT')
READ(10,*)HEIGHT
READ(11,*)WEIGHT
CLOSE(10)
CLOSE(11)
AVEHEIGHT=AVRG(HEIGHT,I)
AVEWEIGHT=AVRG(WEIGHT,I)
WRITE(*,*)'AVERAGE HEIGHT=',AVEHEIGHT
WRITE(*,*)'AVERAGE WEIGHT=',AVEWEIGHT
END PROGRAM HEIGHTANDWEIGHT
FUNCTION AVRG(A,K)
INTEGER ::J
REAL:: SUM,AVRG,A(10)
SUM=0.0
DO J= 1,K
SUM=SUM+A(J)
END DO
Page 9

fortran by rege .txt


AVRG=SUM/K
RETURN
END FUNCTION
________________________________________________________________________________
__________
________________________________________________________________________________
__________
! class work
! ASSUME YOU DONT WANT TO USE FUNCTION 17-02-2014
PROGRAM HEIGHTANDWEIGHT
REAL, DIMENSION(10)::HEIGHT, WEIGHT
REAL:: AVEHEIGHT, AVEWEIGHT, SUMHEIGHT,SUMWEIGHT
INTEGER:: I=10
OPEN(10,FILE='HEIGHT.TXT')
OPEN(11,FILE='WEIGHT.TXT')
READ(10,*)HEIGHT
READ(11,*)WEIGHT
CLOSE(10)
CLOSE(11)
SUMHEIGHT=0
SUMWEIGHT=0
DO J=1,I
SUMHEIGHT=SUMHEIGHT+HEIGHT(J)
SUMWEIGHT=SUMWEIGHT+WEIGHT(J)
END DO
AVEHEIGHT=SUMHEIGHT/I
AVEWEIGHT=SUMWEIGHT/I
WRITE(*,*)'AVERAGE HEIGHT=',AVEHEIGHT
WRITE(*,*)'AVERAGE WEIGHT=',AVEWEIGHT
END PROGRAM HEIGHTANDWEIGHT
________________________________________________________________________________
__________
________________________________________________________________________________
__________
! this program is calculating
!how to obtain the minimum and maximum value of an array
program max_min
real z(5),x,y
write(*,*) 'input d five values'
read(*,*)z
x = minval(z)
write (*,*) x
y = maxval(z)
write (*,*) y
end
________________________________________________________________________________
__________
________________________________________________________________________________
__________
if you really understand how this function works then
calculate average, minimum, maximum,range for
heights, weights and ages of a class
Page 10

fortran by rege .txt


________________________________________________________________________________
__________
________________________________________________________________________________
__________
mediafire download link

------ https://www.mediafire.com/?7kpgw9a960fa398

you can contact the author with this e-mail -----

segzie1616@yahoo.com

________________________________________________________________________________
__________
________________________________________________________________________________
__________

Page 11

S-ar putea să vă placă și