Fortran Assignment-2012015
Fortran Assignment-2012015
Code:
program value_present
implicit none
integer :: A(4,4), n, i, j
logical :: found
do i = 1, 4
do j = 1, 4
if (A(i,j) == n) then
found = .true.
end if
end do
end do
if (found) then
print*, 'The value is present in this Array'
else
print*, 'The value is not present!'
end if
stop
end program
Input Data & Output:
Exercise 01:
[Write a Fortran program which calculates the following up to five decimal places: ]
1 1 1 1
........
1 3 5 21
Code:
program inverse_sum
implicit none
integer :: i
real :: sum
sum = 0.0
do i = 1, 21, 2
sum = sum + (1.0/i)
end do
write(*,99) sum
99 format('The sum of the series is = ', f10.5)
stop
end program
Output:
Exercise 02:
[Write a Fortran program that prints the sum of first fifty odd numbers using Do loop]
Code:
program fifty_sum
implicit none
integer :: i, n
real :: sum
write(*,'(A)', advance = 'no')'How many Odd numbers you want to sum (from
first) = '
read*, n
sum = 0.0
do i = 1, 2*n, 2
sum = sum + i
end do
Output:
Exercise 03:
[Consider the quadratic polynomial y = 2x2 - 3x - 5. Write a Fortran program which finds
y for values of x from - 4 to 4 in steps of 0.5]
Code:
program quadratic_solve
implicit none
integer :: i
real :: x, y, ans(17)
x = -4
do i = 1, 17, 1
y = 2*(x**2) - 3*x - 5
x = x + 0.5
ans(i) = y
print*, y
end do
print*, 'All the reults are : ', ans
stop
end program
Output:
Exercise 04:
[Write a Fortran program to find the smallest of 100 numbers using DO loop]
Code:
program smallest_number
implicit none
real :: X(100), small
integer :: i
read(1,*) X
small = X(1)
do i = 2, 100
if (X(i) < small) then
small = X(i)
end if
end do
stop
end program
Code:
program sectional_area
implicit none
real :: Or(10), SM(10), SM_product, area
integer :: i, h
SM_product = 0.0
do i = 1, 10
SM_product = SM_product + SM(i)*Or(i)
end do
write(3, '(A, f10.3)') 'The sectional area under the curve is (in sq m) =
', area
stop
end program
Input & Output: