Popular Posts

Assignment 1

Saturday, March 3, 2012


ASSIGNEMENT ONE

QUESTION 1(i):Print the positive integers from 1 to N greater or equal to 50 with three numbers to a line


!     Last change:  R     2 Mar 2012    8:03 pm
! Question number 1(I) of assignment one
PROGRAM printing_numbers
! it's a program to printing numbers from 1 to N>=50 three numbers to a line
! Input any number greater or equal to 50
PRINT*, ' Input the last Number:'
READ(*,*) N
! Here is printed the output of your desired program
WRITE(*,*)'Here is printed the output of your desired program'
WRITE(*,10)(i,i=1,n)
10 format (3(2x,I3))
END PROGRAM


QUESTION 1(II):

!     Last change:  R     2 Mar 2012    9:27 pm
! Assignment one question no 1(ii)
! the following program solve sum and product of series
program sum_and_product
1 READ(*,*) n
if (n.lt.2) then
PRINT*, 'wrong input, so recheck the condition and input the value of n again'
GOTO 1
end if
summ=0.0
productt=1.0
! now we are going to produce a formula to calculate the sum
! Let initial sum is zero wich is denoted by summ=0.0
! Now follow the loop.
do i=1,n                          ! here i starts from 1
do j=1,i                          ! if i=1 then j=1 then summ=summ+1/float(j)=0+1=1
                                  ! now the current value of summ=1
summ=summ+1.0/float(j)            ! then if i=2 then j=1,2 then summ=summ+1/float(j)
end do                            !                                 =1+(1/1)+(1/2)
end do                            ! in this way we can calculate the rest part of the program
! now we gonna calculate the product of the given series
! Let the initial product is 1.0, note theat if initial product is zero then final result
! will be also zero. to avoid complexities we define initial productt=1.0
! Now follow the loop
do i=1,n                          ! let i=1
summm=0.0                         ! summm=0 and j=1 and loop for i and j both single time
do j=1,i                          ! and then the value of sum and product both will be 1
summm=summm+1.0/float(j)          ! let i=2 then i loop will move single time and loop of j will
end do                            ! move two times
productt=productt*summm
end do
WRITE(*,10) summ,productt
10 format (2x,' the sum is: ',F10.5,//2x,' the product is: ',F10.5)
end program

0 comments:

Post a Comment