aaloui
Mechanical
- Jul 26, 2011
- 18
Hi,
i just started learning Fortran 77 language, (i have already some programming knowledge in C and Pascal but i need to learn fortran 77 for use in other programm which is based on this language). So i started learning it using a book called "Fortran 77 and numerical methods by C Xavier". There i wanted to test some simple programs, for example this programm for calculating triangle area:
C Program for area of triangle
write(*,1)
1 format(1X,'type the sides A, B, C')
read(*,2) A, B, C
2 format(3F10.3)
S=(A+B+C)/2
Area=SQRT(S*(S-A)*(S-B)*(S-C))
write(*,3) Area
3 Format(1X,'Area=',F10.3)
STOP
END
so the problem when i run the programm is that only the first variable is read "wihtout waiting that i give the second and third variables" and area is directly given as "Area= NaN" some, no error is given while
running, i tried 2 compilers (Intel and Force 2.0.9) with same results. When i modify the format to format(F10.3,F10.3,F10.3) its also not working. What i could do is to read the 3 variables in differents read statements and the program will be like this:
C Program for area of triangle
write(*,1)
1 format(1X,'type the sides A, B, C')
read(*,2) A
2 format(F10.3)
read(*,3) B
3 format(F10.3)
read(*,4) C
4 format(F10.3)
S=(A+B+C)/2
Area=SQRT(S*(S-A)*(S-B)*(S-C))
write(*,5) Area
5 Format(1X,'Area=',F10.3)
PAUSE
STOP
END
In this case its working, so something seems to be wrong in my read and format statement of the 3 variable, i gave exactly the same what is given in the book im using, and there many other programs have read statements in the same manner, so i dont know what im doing wrong or missing. Im very thankful for your support !
Regards.
Ali.
i just started learning Fortran 77 language, (i have already some programming knowledge in C and Pascal but i need to learn fortran 77 for use in other programm which is based on this language). So i started learning it using a book called "Fortran 77 and numerical methods by C Xavier". There i wanted to test some simple programs, for example this programm for calculating triangle area:
C Program for area of triangle
write(*,1)
1 format(1X,'type the sides A, B, C')
read(*,2) A, B, C
2 format(3F10.3)
S=(A+B+C)/2
Area=SQRT(S*(S-A)*(S-B)*(S-C))
write(*,3) Area
3 Format(1X,'Area=',F10.3)
STOP
END
so the problem when i run the programm is that only the first variable is read "wihtout waiting that i give the second and third variables" and area is directly given as "Area= NaN" some, no error is given while
running, i tried 2 compilers (Intel and Force 2.0.9) with same results. When i modify the format to format(F10.3,F10.3,F10.3) its also not working. What i could do is to read the 3 variables in differents read statements and the program will be like this:
C Program for area of triangle
write(*,1)
1 format(1X,'type the sides A, B, C')
read(*,2) A
2 format(F10.3)
read(*,3) B
3 format(F10.3)
read(*,4) C
4 format(F10.3)
S=(A+B+C)/2
Area=SQRT(S*(S-A)*(S-B)*(S-C))
write(*,5) Area
5 Format(1X,'Area=',F10.3)
PAUSE
STOP
END
In this case its working, so something seems to be wrong in my read and format statement of the 3 variable, i gave exactly the same what is given in the book im using, and there many other programs have read statements in the same manner, so i dont know what im doing wrong or missing. Im very thankful for your support !
Regards.
Ali.