Question

In: Computer Science

     i What values would be stored in the given variables in each case? a.          int n =...

     i

What values would be stored in the given variables in each case?

a.          int n = 12 % 5;

b.          double x = 15 % 11 + 5.3 - 5 / (2.5 - 0.3);

c.   float y = 2 / (3.5 + static_cast<int>(3.5));

d.   bool z = (6 – 7 <= 2 * 1) && (5 + 4 >= 3) || (6 + 2 != 17 – 3 * 10);

Solutions

Expert Solution

a.          

int n = 12 % 5;

Here n contain the reminder of 12 / 5 operation.

Since reminder is 2, n=2

Therefore the value of n is 2.

b.

double x = 15 % 11 + 5.3 - 5 / (2.5 - 0.3);

It is evaluated based on the priority order.

() has highest priority so it is evaluated first.

x = 15 % 11 + 5.3 - 5 / 2.2;

% and / has next priority so evaluate it.

x = 4 + 5.3 - 2.27273;

x = 7.02727

Therefore the value of x is 7.02727

c.

float y = 2 / (3.5 + static_cast<int>(3.5));

static_cast<int>(3.5) // It change the value to integer so the value of 3.5 is changed to 3

float y = 2 / (3.5 + static_cast<int>(3.5));

float y = 2 / (3.5 + 3);

float y = 2 / (6.5);

float y = 0.307692

Therefore the value of y is 0.307692

d.

bool z = (6 - 7 <= 2 * 1) && (5 + 4 >= 3) || (6 + 2 != 17 - 3 * 10);

z = ( - 1 <= 2) && (9>= 3) || (8 != 17 - 30); // evaluate 3*10 first because multiplication has high priority

z = ( - 1 <= 2 * 1) && (9>= 3) || (8 != 13);​​

z = ( true) && (true) || (true);​​

z = true

Therefore the value of z is true.


Related Solutions

int f2 (int n) j = 0; while (j <n) {for (int i = 0; i...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i <n; ++ i) {cout << "j =" + j; j = j + 5; }}
1.    Given the following values, evaluate the logical value of each expression.   [3 each] int a...
1.    Given the following values, evaluate the logical value of each expression.   [3 each] int a = 3; int b = 8; int c = 3; int d = 10;               a.            b < c && c < d               b.           !(a == c && c != d) c.            !(d <= b) || (c > a) d.           a == c || c == d 2.           Given the following values, evaluate the logical value of each expression.   [4 each] int g...
What are the critical values of t for each of the following values of N and...
What are the critical values of t for each of the following values of N and alpha using a nondirectional hypothesis? N   a a. 12 0.05 b. 20 0.01 c. 2 0.05 d. 5 0.02 e. 19 0.01 Now using a directional hypothesis? N    a f. 13 0.025 g. 17 0.005 h. 8 0.05 i. 15 0.01 j. 10 0.05
What is time Complexity each of the following function? 1- void function(int n) {             for (int...
What is time Complexity each of the following function? 1- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n/2; j++)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 2- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n; j = 2 * j)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 3- void function(int n) {             for (int i=1; i<=n; i++)                           for (int j=1;...
Given the following int variables which represent a date, int day; // 0-6 for Sunday-Saturday int...
Given the following int variables which represent a date, int day; // 0-6 for Sunday-Saturday int month; // 1-12 for January-December int date; // 1-31 int year; // like 2020 Define the function void tomorrow(int& day, int& month, int& date, int& year); which updates the variables to represent the next day. Test in main().
1. Find all the values of x such that the given series would converge. ∞∑n=1 (3x)^n/n^11...
1. Find all the values of x such that the given series would converge. ∞∑n=1 (3x)^n/n^11 The series is convergent from x =     , left end included (enter Y or N): to x =     , right end included (enter Y or N): 2. Find all the values of x such that the given series would converge. ∞∑n=1 5^n(x^n)(n+1) /(n+7) The series is convergent from x= , left end included (enter Y or N): to x= , right end included (enter Y or...
//2.-------------------------------------------------------------- Given an array of size N, what is the complexity? int m = A[0]; for...
//2.-------------------------------------------------------------- Given an array of size N, what is the complexity? int m = A[0]; for (int i=1; i<N; i++) { if (A[i] > m) m = A[i]; } int k = 0; for (int i=0; i<N; i++) { if (A[i] == m) k++; } What is a (name one) most frequent operation performed?______________________ Expression showing the number of times it is performed ___________ Time Complexity in Big-O Notation O( ) _____________________________________________________ //3.-------------------------------------------------------------- int mult(int N, int M) {   ...
JAVA JAVA JAVA JAVA, My array has 1000 int variables with random values from 1-100, I...
JAVA JAVA JAVA JAVA, My array has 1000 int variables with random values from 1-100, I want to be able to scan and output which number appears the most and the least. int x =1000 int[] array = new array[x] for(int i = 0 ; i < x; i++){ array[i] = random.nextInt(101); }
Identify the possible values of each of the 3 variables in this dataset and describe what...
Identify the possible values of each of the 3 variables in this dataset and describe what information each of the 3 variables tells us about the data Heart rate before and after exercise M=0 F=1 Resting After Exercise 0 85.9 87.5 0 67.7 79.4 0 80.3 93.4 0 85.2 97.7 0 86.3 99.7 0 76.6 83.7
Given the root C++ code: void sort() {    const int N = 10;    int...
Given the root C++ code: void sort() {    const int N = 10;    int x[N];    for(int i = 0; i < N; i++)    {        x[i] = 1 + gRandom-> Rndm() * 10;        cout<<x[i]<<" "; }    cout<<endl;    int t;       for(int i = 0; i < N; i++)    {    for(int j = i+1; j < N; j++)    {        if(x[j] < x[i])        {   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT