Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

figure 4.3.1: while loop example: gcd (greatest common divisor) program…

Question

figure 4.3.1: while loop example: gcd (greatest common divisor) program.
#include <iostream>
using namespace std;
// output gcd of user - input numa and numb
int main() {
int numa; // user input
int numb; // user input
cout << \enter first positive integer: \;
cin >> numa;
cout << \enter second positive integer: \;
cin >> numb;
while (numa != numb) { // euclids algorithm
if (numb > numa) {
numb = numb - numa;
}
else {
numa = numa - numb;
}
}
cout << \gcd is: \ << numa << endl;
return 0;
}

enter first positive integer: 9
enter second positive integer: 7
gcd is: 1
...
enter first positive integer: 15
enter second positive integer: 10
gcd is: 5
...
enter first positive integer: 99
enter second positive integer: 33
gcd is: 33
...
enter first positive integer: 500
enter second positive integer: 500
gcd is: 500

participation activity
4.3.1 gcd program.
refer to the gcd code above. assume user input of numa = 15 and numb = 10.

  1. for the gcd program, what is the value of numa before the first loop iteration?

Explanation:

Step1: Identify user - input values

The user - input values are given as numA = 15 and numB = 10. Before the first loop iteration, the values of the variables are the ones just assigned by user input.

Answer:

15