Answer to Question #339858 in C++ for dave

Question #339858

What is the output of each of the following statements? Assume that

x = 5, y = 2, z = 10, and temp = 0

 

 


1. if (y >= x)

      y = z;

   cout<< x << " " << y << " " << z << endl;

 

2. if (y >= x)

   {

      y = z;

      cout<< x << " " << y << " " << z << endl;

   }

 

3. if (z < y)

      temp = x;

      x = z;

   z = temp;

   cout<< x << " " << y << " " << z << endl;

 

 

4. if (z > y)

   {

      temp = x;

      x = z;

      z = temp;

   }

   cout<< x << " " << y << " " << z << endl;

 


5. if (x >= 6)

   cout<< x + y << endl;

   cout<< x + y << endl;

 

 

 

6. if (x + y > z)

      x = y + z;

   else

      x = y - z;

   cout<< x << " " << y << " " << z << endl;


1
Expert's answer
2022-05-11T08:48:48-0400
#include<iostream>


using namespace std;


int main()
{
	int x = 5, y = 2, z = 10, temp = 0;
	if (y >= x)
		y = z;
	cout <<"1. "<< x << " " << y << " " << z << endl;
	x = 5, y = 2, z = 10, temp = 0;
	if (y >= x)
	{
		y = z;
		cout<<"2. " << x << " " << y << " " << z << endl;
	}
	x = 5, y = 2, z = 10, temp = 0;
	if (z < y)
		temp = x;
	x = z;
	z = temp;
	cout<<"3. " << x << " " << y << " " << z << endl;
	x = 5, y = 2, z = 10, temp = 0;
	if (z > y)
	{
		temp = x;
		x = z;
		z = temp;
	}
	cout<<"4. " << x << " " << y << " " << z << endl;
	x = 5, y = 2, z = 10, temp = 0;
	if (x >= 6)
		cout<<"5. " << x + y << endl;
	cout<<"5. " << x + y << endl;
	x = 5, y = 2, z = 10, temp = 0;
	if (x + y > z)
		x = y + z;
	else
		x = y - z;
	cout<<"6. " << x << " " << y << " " << z << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS