Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5.12, Problem 5.10PP
A.
Program Plan Intro
Given C Code:
void copy_array(long *src, long *dest, long n)
{
long i;
for(i=0; i<n; i++)
dest[i] = src[i];
}
Cycles per element (CPE):
- The CPE denotes performance of program that helps in improving code.
- It helps to understand detailed level loop performance for an iterative
program. - It is appropriate for programs that use a repetitive computation.
- The processor’s activity sequencing is controlled by a clock that provides regular signal of some frequency.
B.
Program Plan Intro
Given C Code:
void copy_array(long *src, long *dest, long n)
{
long i;
for(i=0; i<n; i++)
dest[i] = src[i];
}
Cycles per element (CPE):
- The CPE denotes performance of program that helps in improving code.
- It helps to understand detailed level loop performance for an iterative program.
- It is appropriate for programs that use a repetitive computation.
- The processor’s activity sequencing is controlled by a clock that provides regular signal of some frequency.
C.
Program Plan Intro
Given C Code:
void copy_array(long *src, long *dest, long n)
{
long i;
for(i=0; i<n; i++)
dest[i] = src[i];
}
Cycles per element (CPE):
- The CPE denotes performance of program that helps in improving code.
- It helps to understand detailed level loop performance for an iterative program.
- It is appropriate for programs that use a repetitive computation.
- The processor’s activity sequencing is controlled by a clock that provides regular signal of some frequency.
D.
Program Plan Intro
Given C Code:
void copy_array(long *src, long *dest, long n)
{
long i;
for(i=0; i<n; i++)
dest[i] = src[i];
}
Cycles per element (CPE):
- The CPE denotes performance of program that helps in improving code.
- It helps to understand detailed level loop performance for an iterative program.
- It is appropriate for programs that use a repetitive computation.
- The processor’s activity sequencing is controlled by a clock that provides regular signal of some frequency.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Subject : programming
language : c++
Question :
Write c++ program and test the following functions :void multiply (float a[ ], int n, float b [ ] );The function multiplies the first n elements of a by corresponding first n elements of b. For example: if a is the array {2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9} and b is the array {4.0,-3.0, 2.0,-1.0, 0.0,0.0} Then the call multiple (a, b, 5) would transform a into the array {8.8, - 9.9, 8.8, - 5.5,0.0,7.7, 8.8,9.9}
1)
Consider an integer array a of length n with indexing starting at 0, where n is a positive integer.If the elements of array a are to be written out in reverse order, which of the following C++ code fragment does NOT do the job?
Question options:
a. int i=n-1; while (i>=1){cout << a[i] << endl; i = i-1;} cout << a[i] << endl;
b. int i=n-1; while (i>=1){cout << a[i] << endl; i = i-1;}
c. int i=n-1; while (i>=0){cout << a[i] << endl; i = i-1;}
d. int i=n; while (i>0){cout << a[i-1] << endl; i = i-1;}
2)
Assume we use 8-bit cell to store floating point numbers, 1 bit for sign, 3 bits for excessed exponent, and 4 bits for significand. What is the decimal value for a cell with bit pattern 0 111 1101
Question options:
a. 125
b. 224…
PYTHON/ COMPUTATIONAL STOICHIOMETRY
Please help me build the stochiometric matrix for the chemical reaction.kindly use the code provided to guide your solution.
1.7 A + 2.1 B + 1.5 C <=> 3 D + 3.8 E + 1.2 F
Code Block to build stoichiometric matrix:
import numpy as np
# Initialize the stoichiometric matrix as zeros_mtrx = np.zeros((len(reactions), len(species)))
for (i_row, r) in enumerate(reactions): left = r.split('<=>')[0].strip() right = r.split('<=>')[1].strip() left_terms = left.split('+') left_terms = [t.strip() for t in left_terms] # in-place clean up right_terms = right.split('+') right_terms = [t.strip() for t in right_terms] # in-place clean up for t in left_terms: # reactants tmp = t.split(' ') # split stoichiometric coeff and species name if len(tmp) == 2: # stoich coeff and species name coeff = float(tmp[0].strip()) species_member = tmp[1].strip() j_col…
Chapter 5 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- c) What is the content of matrix C after execution the void function Exum, when A-{{I, 31.1. 3/: B-1, 3).1. 311: and the function Exam is: void Exam (int A21, int BI{21, int CI[2) I int i j, k. s0; for (i-0: i<2; ++ I for (-0;j< 2: jt) for (k-0; k< 2; k++ Ci) = s:arrow_forwardProblem #1 Write the function divideArray() in script.js that has a single numbers parameter containing an array of integers. The function should divide numbers into two arrays, evenNums for even numbers and oddNums for odd numbers. Then the function should sort the two arrays and output the array values to the console. Ex: The function call: let nums = | = divideArray(nums); produces the console output: [4, 2, 9, 1, 8]; Even numbers: 2 4 8 Odd numbers: 1 9 The program should output "None" if no even numbers exist or no odd numbers exist. Ex: The function call: let nums = [4, 2, 8]; divideArray(nums); produces the console output: Even numbers: 2 4 8 Odd numbers: None Hints: Use the push() method to add numbers to the evenNums and oddNums arrays. Supply the array sort() method a comparison function for sorting numbers correctly. To test your code in your web browser, call divideArray() from the JavaScript console.arrow_forwardI have a question about programming in C(89) C. Could someone please show me how to make a program that uses a custom function that rearranges array elements from one array of size n into a new larger second array of size (n+1) and places a new element into the new second larger array at a particular index location? For example, the user would be prompted for a size like say, 7. Then the user would be prompted for the seven array element values, which could be like {1, 7, 4, 6, 3, 9, 8}. Then the user gets prompted again for a new element value to add to the new larger second array. Let's say the new value is entered as 5. All of this would be done in main and no pointers are required. Then main calls a custom function called rearrange. the prototype for rearrange must be; void rearrange(int *a, int n, int insert, int *b); After rearrange is done, main would display the contents of the new larger second array like so; {1, 4, 3, 5, 7, 9, 8} Here's the trick though. Please notice…arrow_forward
- (8). an array of integers nums and an integer target, return the indices of the two numbers such that they add up to the target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Explain also.arrow_forwardFor each of the following problems, all functions should be implemented using a call stack. Problem 2: Write a program that defines two integer array that are pre-sorted and the same size (e.g., [3, 7, 9, 11, 15, 21] and [1, 4, 6, 14, 18, 19]) and a function merge that takes the two arrays (and their size) as inputs and populates a single array of twice the size of either input array that contains the elements of both arrays in ascending order. In the example arrays given, then output would be [1, 3, 4, 6, 7, 9, 11, 14, 15, 18, 19, 21]. Have your 'main' function (not the merge function) print out the final array using a comma as a delimiter.arrow_forward2. Task 1: Using Single-Dimensional Array Write a C program that will accept 10 input values and will store the values in array. The program will also identify and print the minimum, maximum and average of input values. NOTE:Your source code must display any of the given sample output below.It means your source code should be flexible enough to meet any of the given sample output.Your source code output must be identical to any of the given sample output.It means you have to strictly follow what are the displayed text, labels, casing of characters in the sample output. OUTPUT 1: Input Value 1: 50 Input Value 2: 20 Input Value 3: 35 Input Value 4: 100 Input Value 5: 75 Input Value 6: 89 Input Value 7: 5 Input Value 8: 11 Input Value 9: 85 Input Value 10: 60 MIN Value: 5 MAX Value: 100 AVG Value: 53 OUTPUT 2: Input Value 1: 10 Input Value 2: 9 Input Value 3: 8 Input Value 4: 7 Input Value 5: 6 Input Value 6: 5 Input Value 7: 4 Input…arrow_forward
- OCAML programming (Lights Out) The mechanics described in this exercise can be used to implement a game lights out. 1. Create a function flip val flip : bool array array -> int -> int -> bool array array = <fun> that given a bool matrix and two integers i; j. it negates the values(true!false, false!true) at location i; j in the matrix, as well negatingthe values on the (up to) 4 horizontally/vertically adjacent elements. 2. Create a function print matrix val print_matrix : bool array array -> unit = <fun> that given a bool matrix, it prints it on screen (true !"T", false!"F"). Sample input: # let matrix= [|[|false; true; true; false|]; [|true; false; false; true|];[|false; false; true; true|]|];;# print_matrix matrix;;FTTFTFFTFFTT# flip matrix 1 4;;# print_matrix matrix;;FTFTTFFFFFTTarrow_forward(a) In this task we consider ptr as a 2D matrix. Whereas, number of rows would be fixed but make number of columns variables. To do this, instead of using arrays of fixed column size allocated on stack, you will make each element of array to have nColumns (passed as argument to the function) elements and store them on heap using new operator. Next, initialize the values of these arrays randomly using for loop and ptr. Finally display the sum of each individual array.You are not allowed to access the array using original variable name. (b) In the previous task we make number of columns of a 2D matrix variables. Here we will make number of rows variables as well. Thus we will have a way of defining a generic 2D matrix according to user choice. Now your goal is to write a function that receives three arguments: (i) an alias to a 2D pointer; (ii)number of rows; and (iii) number of columns; Now your goal is to first allocate the memory for rows and then for columns dynamically using new…arrow_forwardLanguage: JavaScript (Node.js) • Autocomplete Ready O 1 > 'use strict';... 5. Use array.map to double each 26 number 27 / * 28 * Complete the 'double' function below. 29 Use array.map to complete the double function. The function is expected to double each number in an array. 30 * The function is expected to return an INTEGEF 31 * The function accepts INTEGER_ARRAY arr as par 32 * / 33 34 function double(arr) { 35 36 37 38 > function main() {….. Test Results Custom Innut :::::::arrow_forward
- (a) In this task we consider ptr as a 2D matrix. Whereas, number of rows would be fixed but make number of columns variables. To do this, instead of using arrays of fixed column size allocated on stack, you will make each element of array to have nColumns (passed as argument to the function) elements and store them on heap using new operator. Next, initialize the values of these arrays randomly using for loop and ptr. Finally display the sum of each individual array.You are not allowed to access the array using original variable name. (b) In the previous task we make number of columns of a 2D matrix variables. Here we will make number of rows variables as well. Thus we will have a way of defining a generic 2D matrix according to user choice. Now your goal is to write a function that receives three arguments: (i) an alias to a 2D pointer; (ii)number of rows; and (iii) number of columns; Now your goal is to first allocate the memory for rows and then for columns dynamically using new…arrow_forwardQuestion 2. Write a C++ program to perform following tasks: Declare a dynamic array of size 's'. Take input in s from user b. Fill the array with random numbers between 1 and 100 using built-in rand() function а. (https://www.cplusplus.com/reference/cstdlib/rand/) Find all the even and odd numbers and implement following array of pointes. C. Array of even numbers Array of odd numbers d. Write a function void Display(int **x, int size) and call it appropriately for array created in part c.arrow_forwardProblem 1: In the main function, declare 3 two-dimensional arrays (arr1, arr2 and result) of the float type, representing two-dimensional matrices. The size of the array is defined with #define SIZE 3. Write a function that assigns pseudo-random values to all the elements of the two- dimensional array. Call that function for two previously declared arrays. Write a function that prints all the elements of the two-dimensional array. Call that function for two previously initialized arrays. All functions are of the void type. Problem 2: Write the functions that will calculate the result of adding, and multiplying two matrices and store the result in a third matrix. Any matrix Amxn may be represented by its entries amn Amxn = Problem 3: a11 a 12 a21 a22 am1 am2 amn In order to add the matrices A and B, C = A+B you just add their entries, i.e., Cmn = amn+bmn. Multiplication of the matrices A and B, C = A B is more complicated. It is given by the formula Cmn = 1 amibin, where N is the order…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education