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;
//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
Comments
thank you very much
Leave a comment