Learning Activity 4 - Lim

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

JAC ANGELO T.

LIM
BSCE – 1A

Check your understanding!


1. Show the result of the following using the indicated operations:
a. 5 % 6 = 5 b. 34 / 18 = 1
c. 68 % 4 = 0 d. 34 / 5 = 6
e. 5 % 1 = 0 f. 7 | 4 = 7
g. 5 & 3 = 1 h. 4 << 2 = 16
i. 9^4 = 13 j. 10 >> 2 = 2

2. Evaluate if each of the following statement is true or false.


a. (15>= 3 *5 || 25 >= 24 +2) && 12<=25/3 && 22 - -34 >= 20;

Answer: (15>= 3 *5 || 25 >= 24 +2) //evaluates to true && 12<=25/3 && 22 - -34 >= 20; //evaluates to
false.

b. 10 > 25 && !(30!=25) || 10 + 20== 45 - 10;

Answer: 10 > 25 && !(30!=25) //evaluates to false || 10 + 20== 45 - 10; //evaluates to false.

3. What is the result of 25 / 4? How would you rewrite the expression if you wished the result to be a
floating-point number?
It rewrite as 25.0 / 4.0, 25.0 / 4, or 25 / 4.0. or in the program…
4. Suppose m and r are integers. Write two different ways of C++ expression for mr^2, store the result
to variable result. The other expression uses the math function for r^2 and the other doesn’t use the
math function but the equivalent expression.

Answer:

5. Show the result of the following code:

cout << 2 * (5 / 2 + 5 / 2) << endl; //_______


cout << 2 * 5 / 2 + 2 * 5 / 2 << endl; //_______
cout << 2 * (5 / 2) << endl; //_______
cout << 2 * 5 / 2 << endl; //_______
6. Are the following statements correct? If so, show the output. cout << "25 / 4 is " << 25 / 4 << endl;
//________ cout << "25 / 4.0 is " << 25 / 4.0 << endl; //________ cout << "3 * 2 / 4 is "
<< 3 * 2 / 4 << endl; //________ cout << "3.0 * 2 / 4 is " << 3.0 * 2 / 4 << endl;
//________

Answer: Yes, it is correct and the output is…


7. Show the printout of the following code:

int a = 6; int b = a-
int a = 6; int b = -; int c = --b + a;
a++; int c = ++b + cout << a << endl;
a++; cout << a << cout << b << endl;
endl; cout << b << cout << c << endl;
endl;
cout << c << endl;

Result: program 1

Result: Program 2
8. Write the line of code for the following statements.
a. Declare a string named favFood. Int string favfood;
b. Assign a value pizza to that variable of letter a.
favfood=a;
c. Stream in the string from input.
cin >> facfood;
d. Declare and assign string named age String as “25”.
String agestring = 25
e. Extract the age String value to integer value named age.
Int agestring, age; // a:?, b:? agestring = 25;
// a:25, b:? age= a // a:25, b:25
age= 25 // a:25, b:25

You might also like