Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: Simple Prog...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 34 Topic 8551 of 8908
Post > Topic >>

Re: Simple Program, Lots of Issues (F90)

by Dick Hendrickson <dick.hendrickson@[EMAIL PROTECTED] > Jul 24, 2008 at 06:06 PM

ALevenson wrote:
> I just picked up Fortran yesterday at the suggestion of my mentor,
> which for me means I glance through a tutorial and try to get a
> program running that finds primes. I wrote this over the course of
> maybe 15 minutes, debugged it as I was able to over the next 20, and I
> don't think it is even close to compiling. Of course, I can't figure
> out the exact issues with it, so any help would be appreciated.

Why do you think there are "issues".  If you've tried to compile it,
fix the things you understand and try to compile again.  Repeat
until you don't understand it and then show us what happened.

> 
>       program primes
> 
>       integer :: i, j, k, l, m, n, x
>       real    :: t
>       logical :: notprime, even
> 
> ! Program finds primes up to
> ! upper limit 'x' as defined by user
> 
>       write ( * , * ) 'Please input upper limit, x:'
>       read ( * , * ) x
> 
>       do i = 2, x, 1
prime specific hint.
          write (*,*) 2
         do i = 3 , x, 2
If you do that, you won't have to worry about the evenness
stuff, just test the odd numbers starting at 3.


> ! Form of FOR loop is
> ! do variable = start val, end val, step size
>          if ( i == 2 ) then
>             write ( * , * ) i
>          end if
>          even = .FALSE.
>          notprime = .FALSE.
>          j = i / 2
>          t = i / 2
>          if ( j == t ) then
Why would you ever expect j and t to be different?  Division
is usually repeatable on most machines ;) .
>             even = 1
>          else
>             l = SQRT( i )
The Fortran SQRT function requires a real argument, not an
integer.  Try SQRT(REAL(I)), although there is a better
way that doesn't need a SQRT
>             do m = 3, l, 2
>                n = m / 2
>                t = m / 2
>                if ( n == t ) then
Ditto for n and t
>                   notprime = 1
>                end if
>             end do
>          end if
>          if ( notprime == .FALSE. && even == .FALSE. ) then
>             write ( * , * ) i
>          end if
>       end do
> 
>       stop
>       end
 




 34 Posts in Topic:
Simple Program, Lots of Issues (F90)
ALevenson <Andrew.Leve  2008-07-24 10:55:18 
Re: Simple Program, Lots of Issues (F90)
ALevenson <Andrew.Leve  2008-07-24 10:59:09 
Re: Simple Program, Lots of Issues (F90)
Craig Powers <craig.po  2008-07-24 14:11:46 
Re: Simple Program, Lots of Issues (F90)
Paul van Delst <Paul.v  2008-07-24 14:15:22 
Re: Simple Program, Lots of Issues (F90)
Dick Hendrickson <dick  2008-07-24 18:06:28 
Re: Simple Program, Lots of Issues (F90)
Craig Powers <craig.po  2008-07-24 14:09:35 
Re: Simple Program, Lots of Issues (F90)
ALevenson <Andrew.Leve  2008-07-24 11:12:13 
Re: Simple Program, Lots of Issues (F90)
Craig Powers <craig.po  2008-07-24 14:15:20 
Re: Simple Program, Lots of Issues (F90)
ALevenson <Andrew.Leve  2008-07-24 11:19:35 
Re: Simple Program, Lots of Issues (F90)
Alois Steindl <Alois.S  2008-07-24 20:28:47 
Re: Simple Program, Lots of Issues (F90)
Sebastian Hanigk <hani  2008-07-24 20:45:13 
Re: Simple Program, Lots of Issues (F90)
ALevenson <Andrew.Leve  2008-07-24 11:40:38 
Re: Simple Program, Lots of Issues (F90)
Gib Bogle <bogle@[EMAI  2008-07-25 09:47:44 
Re: Simple Program, Lots of Issues (F90)
dpb <none@[EMAIL PROTE  2008-07-24 17:43:53 
Re: Simple Program, Lots of Issues (F90)
"Kevin G. Rhoads&quo  2008-07-25 20:29:05 
Re: Simple Program, Lots of Issues (F90)
dpb <none@[EMAIL PROTE  2008-07-25 17:21:03 
Re: Simple Program, Lots of Issues (F90)
Richard L Walker <rlwa  2008-07-25 19:06:03 
Re: Simple Program, Lots of Issues (F90)
dpb <none@[EMAIL PROTE  2008-07-25 19:15:40 
Re: Simple Program, Lots of Issues (F90)
Ron Ford <ron@[EMAIL P  2008-07-25 01:36:42 
Re: Simple Program, Lots of Issues (F90)
e p chandler <epc8@[EM  2008-07-25 06:57:35 
Re: Simple Program, Lots of Issues (F90)
Ron Ford <ron@[EMAIL P  2008-07-25 16:57:39 
Re: Simple Program, Lots of Issues (F90)
"Dr Ivan D. Reid&quo  2008-07-25 23:12:58 
Re: Simple Program, Lots of Issues (F90)
e p chandler <epc8@[EM  2008-07-25 17:14:15 
Re: Simple Program, Lots of Issues (F90)
nospam@[EMAIL PROTECTED]   2008-07-25 17:30:39 
Re: Simple Program, Lots of Issues (F90)
Ron Ford <ron@[EMAIL P  2008-07-25 22:49:22 
Re: Simple Program, Lots of Issues (F90)
e p chandler <epc8@[EM  2008-07-25 18:02:47 
Re: Simple Program, Lots of Issues (F90)
AnotherSquid <mai@[EMA  2008-07-29 07:26:26 
Re: Simple Program, Lots of Issues (F90)
"Dr Ivan D. Reid&quo  2008-07-29 19:07:40 
Re: Simple Program, Lots of Issues (F90)
Reinhold Bader <Bader@  2008-07-29 21:19:21 
Re: Simple Program, Lots of Issues (F90)
Craig Powers <craig.po  2008-07-29 15:29:20 
Re: Simple Program, Lots of Issues (F90)
"Dr Ivan D. Reid&quo  2008-07-29 22:51:25 
Re: Simple Program, Lots of Issues (F90)
Tobias Burnus <burnus@  2008-07-29 11:39:10 
Re: Simple Program, Lots of Issues (F90)
kargl@[EMAIL PROTECTED]   2008-07-29 19:29:07 
Re: Simple Program, Lots of Issues (F90)
AnotherSquid <mai@[EMA  2008-07-30 06:49:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Nov 19 9:39:45 CST 2008.