- #1
- 2,168
- 193
1. The problem statement, all variables, and given/known data
So we need to make a flowchart of GCD
2. Homework Equations
Here my codes but something bothers me,
1-Take two positive integers N and M
2-If N>M go to step 3
3-K=M
4=K=K-1
5-Check, If K=1 go to step 11, otherwise, go to step 6
6-Calculate N%K
7-If N%K is zero go to step 8 otherwise go to step 4
8-Calculate M%K
9-If N%K is zero go to step 10, otherwise, go to step 4
10-Print "GCD is K"
11-Print "GCD is 1"
so here in the second line If M>N then I should write the same steps for that result also ?
Another thing is that K=K-1 and K=M terms bother me but I don't know how else I can find it.
So my logic is taking 2 numbers and then choosing the small one. Then dividing the small number with both numbers by reducing 1 in each step. And when the remaining is zero for both numbers we will now that that number "K" is the GCD
So we need to make a flowchart of GCD
2. Homework Equations
The Attempt at a Solution
Here my codes but something bothers me,
1-Take two positive integers N and M
2-If N>M go to step 3
3-K=M
4=K=K-1
5-Check, If K=1 go to step 11, otherwise, go to step 6
6-Calculate N%K
7-If N%K is zero go to step 8 otherwise go to step 4
8-Calculate M%K
9-If N%K is zero go to step 10, otherwise, go to step 4
10-Print "GCD is K"
11-Print "GCD is 1"
so here in the second line If M>N then I should write the same steps for that result also ?
Another thing is that K=K-1 and K=M terms bother me but I don't know how else I can find it.
So my logic is taking 2 numbers and then choosing the small one. Then dividing the small number with both numbers by reducing 1 in each step. And when the remaining is zero for both numbers we will now that that number "K" is the GCD
Last edited: