Asked by EDWIN
FORTRAN ROGRAM THAT CAN ACCEPT TWO INTEGER NUMBERS AND COMPUTE AND DISPLAY ALL THEIR COMMON PRIME FACTORS
Answers
Answered by
MathMate
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
Answered by
EDWIN
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
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.