Question 3: Suppose that you have the following variable declarations: int x = 2
ID: 664798 • Letter: Q
Question
Question 3: Suppose that you have the following variable declarations:
int x = 20;
int y = 35;
int z = 40;
Determine whether the following expressions are true or false.
a. !(x < 100)
b. x <= 5 || y > 15
c. (x != 5) && (y == z)
d. x <= z && (x + y >= z)
Question 5: What is the output from the following C++ code fragment?
int x = 100;
if (x <= 0)
{
cout << “x is a non-positive value” << endl;
}
Question 6: What is the output from the following C++ code fragment?
int x = 0;
if (x < 0)
{
cout << “x is a negative value” << endl;
}
else
{
cout << “x is a non-negative value” << endl;
}
Explanation / Answer
given x =20, y=35, z=40
a) !(x<100)
firstly x<100 ==>20<100 ==>true but !True ===>False
b) x<=5 || y>15
20<=5 False
35>15 ==> true
so OR operator true
c) (x!=5)&&(y==z)
(20!=5)&&(35==40)
False && False
False
d) x <= z && (x + y >= z)
20 <=40 && (20 + 35 >=40)
true && true
True
----------------------------------------------------------
question 5:
int x = 100;
if (x <= 0)
{
cout << “x is a non-positive value” << endl;
}
since x is positive number and greater than zero...so it doesn't pass inside is loop...So i doesnt print anything
------------------------------------------------------
int x = 0;
if (x < 0)
{
cout << “x is a negative value” << endl;
}
else
{
cout << “x is a non-negative value” << endl;
}
since x is given zero....first it check with if condition x<0....but xis not less than zero..it is zero
So, it goes through else condition...so it print " x is a non-negative value"
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.