CS101 Introduction to Computer Utilization and Programming 3/9/2003 Time: 2 hours (Positively answer on the question paper itself. Make sure the paper contains 3 pages). Q.1 Do as directed (No justification for the answer should be given): (a) Von Neumann bottleneck arises due to limited number of registers in the CPU: True or False? False (b) Assignment to an intent(in) formal parameter will give rise to runtime error: True or false? False (c) If 'd' is the number of digits after the decimal point, then the format statement in the scientific 'e' notation is ___________ . (fill in the blank) es(d+5+k).d where k is the no of digits in the exponent. (d) The mantissa determines the ____________ and the exponent determines the ______________ of the real number (fill in the blanks) precision, range (e) In 2's complement notation -25 will be represented as ______________. (fill in the blank) 100111 (f) In the memory, the location next to a(1,1) is a(__,__). (fill in) a(2,1) (g) In fortran 90 a function can call only another function and not subroutines: True or False? False (h) Recursive programs are typically need more runtime memory and time; still they are preferred for better _______________ of programming. (fill in) expressibility (i) The variable 'Str' contains the string 'midsem' (without quotes). What substring operation will extract the 'sem' part? str(4:) Q.2 The following program is supposed to search for an item in a SORTED array of positive numbers recursively. Fill in the ?? marked statements (see the <--). program binsearchmain implicit none integer, parameter :: maxsize = 100 integer, dimension(??) :: nums <---- maxsize integer :: nvals ! Number of data read integer :: i,item,loc,binsearch !loc is the position of item in the array write (*,'("Give the number of elements in the array")') read *, nvals write (*,'("Give the elements")') read *, (nums(i), ??) <---- i=1,nvals do write (*,*) write (*,'("What number do you want to look for?")') read (*,*) item if (item <=0) then write (*,'("Terminating")') exit end if loc= binsearch(nums,nvals,item) if (loc==0) then write(*,'("Item not found")') else write (*,10) item, loc 10 format ("item=",i3," found at position=",i3) end if end do end program binsearchmain recursive integer function binsearch(arr, size, val) result(ans) integer, intent(in) :: size, val integer, dimension(size), intent(in) :: arr integer :: pos ??:: ans <----- integer pos = (?? + size)/2 ! look at the middle element <--- 2 if (pos == 1) then if (arr(pos) == val) then ans = 1 else ans = ?? <----- 0 end if else if (arr(pos) == val) then ans = pos else if (arr(pos) > val) then ans=binsearch(arr(1:pos-1), pos-1, val) else ans=binsearch(arr(??),??, val) <------ pos+1:size size-pos if (??) then <------ ans>0 ans = ans + pos end if end if end if end function binsearch Mark: 1+1+1+1+2+2+2=10 Q.3 This question proposes to test your capability of thinking recursively on a problem and turning it into a fortran 90 program. Do not worry about efficiency issues. Write a program that calls a suitable RECURSIVE subroutine to transpose an input SQUARE matrix. Give the basic idea first in brief. Use both sides of the page, if needed. idea: exchange 1st the with the 1st column and then recursively transpose the rest of the matrix. (subject to compiler limitation) program tranpose_matrix implicit none integer,parameter:: row=3,col=3 integer, dimension(row,col):: a print *, "Give matrix values" call readm(a,row,col) print *, "Before transposing" call printm(a,row,col) call xposem(a,row,col) print *, "After transposing" call printm(a,row,col) end program subroutine readm(a,row,col) implicit none integer,intent(in)::row,col integer,dimension(row,col),intent(inout)::a integer:: i,j read *, ((a(i,j), j=1,col), i=1,row) end subroutine recursive subroutine xposem(a,row,col) implicit none integer,intent(in)::row,col integer,dimension(row,col),intent(inout)::a integer:: i,temp print *, "xposem called with row=",row," and col=",col call printm(a,row,col) if (row==1 .and. col==1) then return else do i=2,row temp=a(i,1) a(i,1)=a(1,i) a(1,i)=temp end do call xposem(a(2:row,2:col),row-1,col-1) end if end subroutine subroutine printm(a,row,col) implicit none integer,intent(in)::row,col integer,dimension(row,col),intent(inout)::a integer:: i,j do i=1,row do j=1,col write(*,'(i3)',advance='no') a(i,j) end do write(*,*) end do end subroutine