Answer to Question #339104 in C++ for alemante teju

Question #339104

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-09T14:54:27-0400
#include <iostream>
using namespace std;
int main(){
	int x = 5, y = 2, z = 10, temp = 0;
	//1
	if (y >= x)
	    y = z;
	cout<< x << " " << y << " " << z << endl;
	return 0;
}

Output:

5 2 10


#include <iostream>
using namespace std;
int main(){
	int x = 5, y = 2, z = 10, temp = 0;
	//2
	if (y >= x){
	    y = z;
	    cout<< x << " " << y << " " << z << endl;
	}
	return 0;
}

Output:


#include <iostream>
using namespace std;
int main(){
	int x = 5, y = 2, z = 10, temp = 0;
	//3	
	if (z < y)
	   temp = x;
	x = z;
	z = temp;
	cout<< x << " " << y << " " << z << endl;
	return 0;
}

Output:

10 2 0


#include <iostream>
using namespace std;
int main(){
	int x = 5, y = 2, z = 10, temp = 0;
	//4
	if (z > y){
	    temp = x;
		x = z;
	    z = temp;
	}
	cout<< x << " " << y << " " << z << endl;
	return 0;
}

Output:

10 2 5


#include <iostream>
using namespace std;
int main(){
	int x = 5, y = 2, z = 10, temp = 0;
	//5	
	if (x >= 6)
	   cout<< x + y << endl;
	cout<< x + y << endl;
	return 0;
}

Output:

7


#include <iostream>
using namespace std;
int main(){
	int x = 5, y = 2, z = 10, temp = 0;
	//6	
	if (x + y > z)
	    x = y + z;
	else
	    x = y - z;
    cout<< x << " " << y << " " << z << endl;
	return 0;
}

Output:

-8 2 10

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

alemante teju
07.07.22, 15:29

thank you very much

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS