what will be the output of the following program segment: int x=3, y = 17; cout << x/y <<y/x << (y/x) + (x % y);
Question
what will be the output of the following program segment: int x=3, y = 17; cout << x/y <<y/x << (y/x) + (x % y);
Solution
The output of the program segment will be 05.
Here's the step by step explanation:
-
x/ywill be 0 because both x and y are integers and integer division of 3/17 gives 0 as 3 is less than 17. -
y/xwill be 5 because both y and x are integers and integer division of 17/3 gives 5 as the quotient. -
(y/x) + (x % y)will be 5 + 3 = 8. Here,y/xis 5 as explained above andx % yis 3 because the remainder of 3/17 is 3 as 3 is less than 17.
So, the output will be 0 (from x/y), 5 (from y/x), and 8 (from (y/x) + (x % y)). But since these are all printed together without any spaces or other separators, they will appear as 058.
Similar Questions
. Find the output of the following program.main(){ int i = (1, 2, 3); cout << i << endl;}
What will be the output of the following program?#include <iostream>using namespace std;int main() { int x, y; x = 5; y = x++ * ++x; cout << x <<" " << y; return 0; }Select one:7 3536 3625 256 49
What will be the output of the following program?#include <iostream>using namespace std;int main() { int i = 3; int l = i / -2; int k = i % -2; cout << l << " " << k; return 0; }Select one:-1.5 -1-1.5 -1.97-1 1-1 -1
Find the output of the following program.main(){ cout << -10 - 10 -10;}
What will be the output of the following code? int main() {int x = 5;int * ptr = &x;*ptr + 1;cout << (*ptr)++;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.