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/y
will be 0 because both x and y are integers and integer division of 3/17 gives 0 as 3 is less than 17. -
y/x
will 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/x
is 5 as explained above andx % y
is 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 following program?main( ){int k, num = 30 ;k = ( num > 5 ? ( num <= 10 ? 100 : 200 ) : 500 ) ;printf ( "\n%d", num ) ;}
What will be the output of the following code? int i = 1;while(i<10){ if (i / 2 == 2) cout << i << “ ”;i++;}
What will this code print? #includeusing namespace std;int x = 7;int main(){int x = 2;{int x = 3;cout << ::x << endl;}return 0;}
What is the output of the following code snippet?int x = 5;int y = 2;int result = x % y;System.out.println(result);Question 2Answera.3b.2c.1d.0
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.