Documente Academic
Documente Profesional
Documente Cultură
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
________________________________________________________________________________
__________
________________________________________________________________________________
__________
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
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
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
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
=
=
=
=
=
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
________________________________________________________________________________
__________
________________________________________________________________________________
__________
!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
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
------ https://www.mediafire.com/?7kpgw9a960fa398
segzie1616@yahoo.com
________________________________________________________________________________
__________
________________________________________________________________________________
__________
Page 11