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;
#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;
}
Comments
Leave a comment