Programming 1
Programming 1
Answer:
(b) Invalid
Answer:
Answer
(a) 13/5*6
Answer 13/5*6=>2.6*6=15.6
(b) 2+5*2-5
Answer 2+5*2-5=>2+10-5=>12-5=7
(c) (2+5)*2-5
Answer (2+5)*2-5=>7*2-5=>14-5=9
(d) 3**3**2
3**3**2=>3*9=>19683
(e) 3**(3**2)
=3**3**2=>3**9=>19683
Answer
Read t
IF(t>=0.) THEN
Fun=(-3)*t**2+5
ELSEIF(t<0)THEN
Fun=3*t**2+1.25
END IF
FUNCTION Lagrange(x, y, n, x)
Sum = 0
DO i = 0, 1, 2
Product f(xi)
DO j = 0, 1, 2
IF i /= j THEN
Product = Product*(x-xj)/(xi-xj)
ENDIF
END DO
sum = sum + product
END DO
Lagrange = sum
END Lagrange
PROGRAM funt
! Purpose:
! This Program solves the function y(t) for a user specified t,
! Where y(t) is defined as:
! Y (t) = |(-3)*t**2 + 5 t >= 0
! | 3*t**2 + 5 t < 0
! Recorded of revisions
Implicit none
!Data dictionary: declare variable types, definitions, & units
REAL :: t ! Independent variable
REAL :: fun ! Resulting function
! Prompt the user for the values t
WRITE (*) 'Enter the coefficient t: '
READ (*) t
! Calculate the function y(t) based upon the signs of t.
IF ( t >= 0. ) THEN
Fun = (-3)*t**2 + 5
ELSE IF ( t < 0. ) THEN
Fun = 3*t**2 + 5
END IF
! Write the value of the function.
WRITE (*) 'The value of the function is: ', fun
END PROGRAM funt
Answer
Program grades
Implicit none
Real:: test1, test2, test2
Integer:: testave
! Display initial header
Write (*,*) "Grade Assignment Program"
Write (*,*)
Write (*,*) "Enter test 1, test 2 and test 3 values“
Read (*,*) test1, test2, test3
! Calculate the average and convert to integer
testave = nint ((test1 + test2 + test3)/3.0)
! Determine grade A >= 90, B= 80 – 89, C= 70 – 79, D = 60 –
69, F <= 59
Select case (testave)
Case (90:)
Write (*,*) "Grade is: A"
Case (80:89)
Write (*,*) "Grade is: B"
Case (70:79)
Write (*,*) "Grade is: C"
Case (60:69)
Write (*,*) "Grade is: D"
Case (:59)
Write (*,*) "Grade is: F"
End select
End program grades
(6) Write a FORTRAN program to evaluate the equation y(x) =
x2 – 3x + 2 for all values of x between −1 and 3, in steps of
0.1.
Answer
PROGRAM funx
! Purpose:
! This Program solves the function y(x) for a user specified x,
! Where y(x) is defined as:
! Y(x) = x**2 - 3*x + 2 -1 < x < 3
IMPLICIT NONE
! Data dictionary: declare variable types, definitions, & units
REAL :: x ! Independent variable
REAL :: fun ! Resulting function
! Prompt the user for the values x
WRITE (*) 'Enter the coefficient x:'
READ (*) x
! Calculate the function y(x).
IF ( -1 < x < 3 ) THEN
Fun = x**2 - 3*x + 2
END IF
! Write the value of the function.
WRITE (*) 'The value of the function is: ', fun
END PROGRAM funx