Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is about fortran, can you please find if there is any error of all statemen

ID: 668097 • Letter: T

Question

This is about fortran, can you please find if there is any error of all statement???

•Multiple variables and strings can be displayed with one write statement.
•For example, using the previous declarations,
write (*,*) "Number 1 = ", num1, "Number 2 = ", num2
•This code segment produces the output:
Number 1 = 20 Number 2 = 50
•The information inside the quotes is displayed as is, including capitalization and any spelling errors.
•The type used for output conversion is the type of the variable.
real :: pi = 3.14159
write (*,*) "pi = ", pi
Produces:
pi = 3.14159012
•A read statement is used to assign values provided by input.
•For example, given the variables
integer :: ans1, ans2
then
read (*,*) ans1
will place the number entered by the user on the keyboard into the
memory location specified by the variable ans1.
•The first asterisk specifies the input will be from the default input device, the keyboard.
•The second “*” means specifies default input format, reading the information in 'free format‘ being specified by the input data variable type.
The free format allows the Fortran compiler to determine the appropriate format for the information being read
Example of area
•Calculating the area of a circle.
•The program will input the radius, calculate the circle area, and display the result.
Program circle
! Program to calculate the area of a circle
! Declare variables
implicit none
real :: radius, area
real, parameter :: pi = 3.14159
! Display initial header and blank line
write (*,*) "Circle Area Calculation"
write (*,*)
! Prompt for and read the radius
write (*,*) "Enter Circle Radius"
read (*,*) radius
! Calculate the circle area
area = pi * radius**2
! Display result
write (*,*) "Circle Area: ", area
end program circle
! Calculate a cylinder surface given the input radius and height.
program AreaCylinder
! Declare variables and constants: constants=pi, variables=radius and height
implicit none ! Requires all variables to be declared
real :: radius, height, area
real, parameter :: pi = 3.141592653589793
! Display initial header, prompt (radius, height)
write (*,*) “Calculate surface area of a cylinder."
write (*,*)
write (*,*) “Input the radius and the height.”
read (*,*) radius, height
! Calculate the surface area of a cylinder.
area = 2 * pi * (radius**2 + radius*height)
! Write all the values to the screen.
write (*,*) "radius=", radius,"height=", height, &
"area=", area
end program AreaCylinder

Explanation / Answer

Program circle
! Program to calculate the area of a circle
! Declare variables
implicit none
real :: radius, area
real, parameter :: pi = 3.14159
! Display initial header and blank line
write (*,*) "Circle Area Calculation"
write (*,*)
! Prompt for and read the radius
write (*,*) "Enter Circle Radius"
read (*,*) radius
! Calculate the circle area
area = pi * radius**2
! Display result
write (*,*) "Circle Area: ", area
end program circle


! Calculate a cylinder surface given the input radius and height.
program AreaCylinder
! Declare variables and constants: constants=pi, variables=radius and height
implicit none ! Requires all variables to be declared
real :: radius, height, area
real, parameter :: pi = 3.141592653589793
! Display initial header, prompt (radius, height)
write (*,*) “Calculate surface area of a cylinder."
write (*,*)
write (*,*) “Input the radius and the height.”
read (*,*) radius, height
! Calculate the surface area of a cylinder.
area = 2 * pi * (radius**2 + radius*height)
! Write all the values to the screen.
write (*,*) "radius=", radius,"height=", height, &
"area=", area
end program AreaCylinder

Answer:   There is no error in the given code for calculating both the area of the circle and surface area of the cylinder program code.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote