Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the output of the following program? #include <iostream> using namespace

ID: 3913057 • Letter: W

Question

What is the output of the following program? #include <iostream> using namespace std; int main() { int myNum = 10; int yourNum = 30; if (yourNum % myNum == 3) { yourNum = 3; myNum = 1; } else if (yourNum % myNum == 2) { yourNum = 2; myNum = 2; } else { myNum = 3; } cout << myNum << " " << yourNum << endl; return 0; } What is the output of the following program? #include <iostream> using namespace std; int main() { int myNum = 10; int yourNum = 30; if (yourNum % myNum == 3) { yourNum = 3; myNum = 1; } else if (yourNum % myNum == 2) { yourNum = 2; myNum = 2; } else { myNum = 3; } cout << myNum << " " << yourNum << endl; return 0; } What is the output of the following program? #include <iostream> using namespace std; int main() { int myNum = 10; int yourNum = 30; if (yourNum % myNum == 3) { yourNum = 3; myNum = 1; } else if (yourNum % myNum == 2) { yourNum = 2; myNum = 2; } else { myNum = 3; } cout << myNum << " " << yourNum << endl; return 0; }

Explanation / Answer

Initially myNum is 10.

Initially yourNum is 30;

if (yourNum % myNum == 3) // 30 % 10 == 0 so condition fail

{

yourNum = 3;

myNum = 1;

}

else if (yourNum % myNum == 2)   // 30 % 10 == 0 so condition fail

{

yourNum = 2;

myNum = 2;

}

else // else part is run

{

myNum = 3; // myNum is changed from 10 to 3

}

cout<< myNum << " " << yourNum << endl; // myNum is 3 and yourNum is 30

Output:

3 30

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote