Question
FORTRAN ROGRAM THAT CAN ACCEPT TWO INTEGER NUMBERS AND COMPUTE AND DISPLAY ALL THEIR COMMON PRIME FACTORS
Answers
Surprised some school actually programmes in Fortran. NASA still does though. It's been a while since I last touched the language. If you have written the programme and run into difficulties, I can help you debug, syntax or logic.
In fortran,
read(5,*)I,J
will read in two integers in free format.
write(6,'2I5')I,J
will write I and J up to 5 characters each.
You can use Euclid's algorithm to find the highest common factor, namely:
1. find the difference between I and J, call it K.
2. Divide the smaller of I or J by K and call the remainder R.
3. Replace the bigger of I or J by R and repeat 1 & 2 until R=0 or 1.
If R=0, K is the GCF.
If R=1, the GCF is 1 (i.e. no common factors).
Example:
I=80
J=48
K=I-J=32
R=remainder of 48/32=1 R16
I=16
J=48
K=48-16=32
R=remainder of 16/32=0 R16
I=16
J=16
GCF = 16 = 2^4
In fortran,
read(5,*)I,J
will read in two integers in free format.
write(6,'2I5')I,J
will write I and J up to 5 characters each.
You can use Euclid's algorithm to find the highest common factor, namely:
1. find the difference between I and J, call it K.
2. Divide the smaller of I or J by K and call the remainder R.
3. Replace the bigger of I or J by R and repeat 1 & 2 until R=0 or 1.
If R=0, K is the GCF.
If R=1, the GCF is 1 (i.e. no common factors).
Example:
I=80
J=48
K=I-J=32
R=remainder of 48/32=1 R16
I=16
J=48
K=48-16=32
R=remainder of 16/32=0 R16
I=16
J=16
GCF = 16 = 2^4
thanks mathmate for your response.
we were asked to use WATFOR77 compiler.i'm a newbee as far as programming is concern.
can you pls. write the program the way i can run it in WATFOR77?
thanks
edwin
we were asked to use WATFOR77 compiler.i'm a newbee as far as programming is concern.
can you pls. write the program the way i can run it in WATFOR77?
thanks
edwin
Related Questions
WRITE A SIMPLE BUT A COMPLETE FORTRAN PROGRAM TO COMPUTE THE AVERAGE OF SIX NUMBERS AND DISPLAY THE...
Pkease who can help? I need to know a pseudocode to display the first n positive integers given n fr...
Construct a pseudocode to compute, to display the sum of ten (10) integer numbers and determine the...