Re: exam REVIEW...can anyone help me?



On Dec 11, 6:47 am, e p chandler <e...@xxxxxxxx> wrote:
On Dec 10, 9:09 pm, ucfjoh...@xxxxxxxxx wrote:



Hey I have a final on friday for my fortran class at UCF.  I'm going
over some review problems to prepare for the exam and this program is
puzzling me a little bit at first glance.  I have another final for
another class tomorrow so I need to study for that tonight, so that's
why I don't have any code to post yet on this, but I will work on it
tomorrow and post what I have.  I'm anticipating needing some help
though so I figured I'd get a head start and post this today and see
if it gets people talking about it a little.

Here's the question I ran into on the review:

I need to analyze an array of numbers and do a few different things
with them.  Numbers will be taken from a separate input txt file.
Answers will be printed in a separate output file and in the main
program.  Thats just the logistics, but here's what it really boils
down to:

As George suggests, writing pseudo-code is good. Or how would you do
the problem with pencil and paper?

a.)  Find the average of the list.
b.) If the list consists of two consecutive numbers it should print
those numbers, if not just give an error message.  So if the list is
28598345, the program will output 34
c.) For each number in the list, tell whether the number plus 1  is in
the list or not (i.e. if the number is 4, tell if 5 is in the list or
not) using logical variables to hold results.
d.) Output should tell if each number is odd or even in the set.
Output is in a new array with element of 1 if odd and 0 if even.

1. How many passes do you need to make through the list for each task?
2. What data structure might you use in c)?
3. d) requires a test of divisibility. Remember that integer division
truncates towards 0 in Fortran. How would you calculate quotient and
remainder using only arithmetic operations? How about with intrinsic
functions?

Good luck.

ok, so i'm pretty sure I've got the average thing down. For part b
and c I think I need to make two passes.

for b i think it needs to find each number "n", and then go back
through to see if "n+1" comes next in the list after any "n" and then
print "n,n+1". I don't know how to tell the program in code to check
to see if "n+1" comes next consecutively.

part c is similar except its just finding out if "n+1" is in the list
at all. I'm not sure how to code that and interpret the results.

part d has to do with divisibility, as you said. I know I need to
divide each "n" by "2" and then its basically just finding out if
there is a remainder or not. If there's no remainder, the "n" is
even, and if there is a remainder "n" is odd. I'm not sure how to get
the program to recognize whether there is a remainder or not.

Here is a FRAMEWORK for what I have already for the average and a bit
of extra stuff that I'm anticipating is necessary to do the rest. Any
help you can give me in how to code the rest and telling me if my
assumptions above about b thru d are on track would be great. I think
I get the generally idea of these parts, but I'm not sure exactly how
to code it.



PROGRAM analyzing_array

IMPLICIT NONE

REAL,DIMENSION(:,:),ALLOCATABLE :: List
INTEGER::numtimes,allocatestatus,filestatus

OPEN( UNIT = 1, FILE= 'input_5.txt' , STATUS = "OLD", &
ACTION = "READ", POSITION = "REWIND", IOSTAT = fileStatus)


OPEN( UNIT = 2, FILE= 'output_5.txt' , STATUS = "NEW", &
ACTION = "WRITE", POSITION = "REWIND", IOSTAT = fileStatus)


PRINT *,"Enter the numbers of integers in the list"
READ *,numtimes

ALLOCATE(List(numtimes),STAT=allocatestatus)
IF(allocatestatus /= 0) STOP

PRINT *,"Enter the values in the list"
READ (1,*,IOSTAT = fileStatus)

PRINT *, "The mean of the numbers is", Find_Mean(ITEM,numitems)

CONTAINS

FUNCTION Find_Mean(X,numelem)

INTEGER,PARAMETER :: numitems = 5
REAL,DIMENSION(numitems) :: ITEM

INTEGER,INTENT(IN) :: numelem
REAL, DIMENSION(numelem), INTENT(IN) :: X
REAL :: Find_Mean

Find_Mean = SUM(X)/REAL(numelem)

END FUNCTION Find_Mean

DEALLOCATE(List)

close(1)
close(2)

CONTAINS



END PROGRAM

.



Relevant Pages

  • Re: exam REVIEW...can anyone help me?
    ... over some review problems to prepare for the exam and this program is ... there is a remainder or not. ... I'm not necessarily worried about printing to the output file. ... My exam is tomorrow at noon EST so the earlier you ...
    (comp.lang.fortran)
  • Re: Odd or Even
    ... > you have an even number if there is no remainder. ... >> Public Function IsOddas boolean ... >>> in the Visual Basic component of Visual Studio 2005. ... >>> like Odd and Even elude me. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Odd or Even
    ... meaning. ... you have an even number if there is no remainder. ... >> in the Visual Basic component of Visual Studio 2005. ... >> like Odd and Even elude me. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Odd or Even
    ... He was testing if the LSB was set. ... > you have an even number if there is no remainder. ... >>> in the Visual Basic component of Visual Studio 2005. ... >>> like Odd and Even elude me. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Interesting math
    ... divisible by an even number with no remainder, ... this is, modulus zero. ... divisible by an odd number with no remainder, ... By convention, we also define a number as even ...
    (alt.usage.english)