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; }}
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().
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); }
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...
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])        {   ...
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
Write a method that, given an array of grades stored as double values, computes and return...
Write a method that, given an array of grades stored as double values, computes and return their mean.    Write another method that will return an array of the mean grade obtained by an arbitrary number of student.    This method will take a 2-dimensional array of double values in which each row corresponds to the grade vector    for a different student. You can compute the mean for each row as you did before...    Once you are done,...
What is the Θ( ) for each code segment below? (a) for( int i = 1,...
What is the Θ( ) for each code segment below? (a) for( int i = 1, i<= n, i = i*2){       some constant operation } (b) for( int i = 1, i<= n, i++){      for( int j = 2*i, j<=n, j++){           some constant operation      } } (c) for( int i = 1, i<= n, i = i*2){      for( int j = 1, j<=n, j = j*2){           some constant operation      } }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT