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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.