|
From: Sandrus on 25 Sep 2006 09:11 Hi. My teacher gave us a program to do factorial (n!). But it does not work fine... it always give -12 as resoult. what do i have to do? i'm not shure but i could have misread 1 in i or viceversa from the blackboard. Will you help me? and please, can anyone explain in a simple way the function of DO? Here the program is PROGRAM fattoriale IMPLICIT NONE INTEGER :: n, nfatt, i WRITE(*,*) 'Inserisci un numero' READ(*,*) n nfatt=i DO i = 1,n END DO WRITE(*,*) nfatt STOP END PROGRAM fattoriale
From: David Flower on 25 Sep 2006 09:30 Sandrus wrote: > Hi. My teacher gave us a program to do factorial (n!). > But it does not work fine... it always give -12 as resoult. > what do i have to do? > i'm not shure but i could have misread 1 in i or viceversa from the > blackboard. Will you help me? > > and please, can anyone explain in a simple way the function of DO? > > Here the program is > > PROGRAM fattoriale > IMPLICIT NONE > INTEGER :: n, nfatt, i > WRITE(*,*) 'Inserisci un numero' > READ(*,*) n > nfatt=i (Should read nfatt = 1) > DO i = 1,n (Something missing here, left as an exercise to the student!) > END DO > WRITE(*,*) nfatt > STOP > END PROGRAM fattoriale Dave Flower
From: beliavsky on 25 Sep 2006 09:34 Sandrus wrote: > Hi. My teacher gave us a program to do factorial (n!). > But it does not work fine... it always give -12 as resoult. > what do i have to do? > i'm not shure but i could have misread 1 in i or viceversa from the > blackboard. Will you help me? > > and please, can anyone explain in a simple way the function of DO? Any Fortran textbook or tutorial (links are at http://www.dmoz.org/Computers/Programming/Languages/Fortran/Tutorials/Fortran_90_and_95/ ) will cover DO loops. Your DO loop below is empty. Do some reading so you can ask more intelligent questions. > Here the program is > > PROGRAM fattoriale > IMPLICIT NONE > INTEGER :: n, nfatt, i > WRITE(*,*) 'Inserisci un numero' > READ(*,*) n > nfatt=i > DO i = 1,n > END DO > WRITE(*,*) nfatt > STOP > END PROGRAM fattoriale
From: Sandrus on 25 Sep 2006 10:05 "David Flower" <DavJFlower(a)AOL.COM> ha scritto nel messaggio news:1159191015.145722.23230(a)i3g2000cwc.googlegroups.com... > > Sandrus wrote: >> Hi. My teacher gave us a program to do factorial (n!). >> But it does not work fine... it always give -12 as resoult. >> what do i have to do? >> i'm not shure but i could have misread 1 in i or viceversa from the >> blackboard. Will you help me? >> >> and please, can anyone explain in a simple way the function of DO? >> >> Here the program is >> >> PROGRAM fattoriale >> IMPLICIT NONE >> INTEGER :: n, nfatt, i >> WRITE(*,*) 'Inserisci un numero' >> READ(*,*) n >> nfatt=i > (Should read nfatt = 1) Ok, i'll correct this mistake >> DO i = 1,n > (Something missing here, left as an exercise to the student!) And what's missing, please? I'm getting mad of that... and i have some difficulties to talk in english (as i'm italian), so @beilavsky, sorry if i dont find many information about DO in italian.... >> END DO >> WRITE(*,*) nfatt >> STOP >> END PROGRAM fattoriale > > Dave Flower >
From: e p chandler on 25 Sep 2006 11:12 Sandrus wrote: > "David Flower" <DavJFlower(a)AOL.COM> ha scritto nel messaggio > news:1159191015.145722.23230(a)i3g2000cwc.googlegroups.com... > > > > Sandrus wrote: > >> Hi. My teacher gave us a program to do factorial (n!). > >> But it does not work fine... it always give -12 as resoult. > >> what do i have to do? > >> i'm not shure but i could have misread 1 in i or viceversa from the > >> blackboard. Will you help me? > >> > >> and please, can anyone explain in a simple way the function of DO? > >> > >> Here the program is > >> > >> PROGRAM fattoriale > >> IMPLICIT NONE > >> INTEGER :: n, nfatt, i > >> WRITE(*,*) 'Inserisci un numero' > >> READ(*,*) n > >> nfatt=i > > (Should read nfatt = 1) > > Ok, i'll correct this mistake > > >> DO i = 1,n > > (Something missing here, left as an exercise to the student!) > > And what's missing, please? > I'm getting mad of that... and i have some difficulties to talk in english > (as i'm italian), so @beilavsky, sorry if i dont find many information about > DO in italian.... Insert this statement here - for teaching purposes WRITE(*,*) i > > >> END DO > >> WRITE(*,*) nfatt > >> STOP > >> END PROGRAM fattoriale > > This will show you what happens to the variable i each time you go through the loop. You have already been given a hint to set nfatt to 1 before you enter the loop. It should not be too hard to figure out what you have to do *inside* the loop to the variable nfatt so that the final value of nfatt will be what you want. -- Elliot -- e-mail: epc8 at juno dot com
|
Next
|
Last
Pages: 1 2 3 4 5 6 7 Prev: Exponentiation operator precedence Next: Apology to comp.lang.fortran |