Computer Systems: A Programmer's Perspective (3rd Edition)
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
Question
Book Icon
Chapter 6, Problem 6.37HW
Program Plan Intro

Given Information:

Three different functions are given:

// declare 2-D array

typedef int array_t[N][N];

// function to add values of 2-D array

int sumA(array_t a) {

// variable declaration

int i, j;

int sum = 0;

// traverse through rows

for (i = 0; i < N; i++)

// traverse through elements

for (j = 0; j < N; j++) {

// sum of elements

sum = sum + a[i][j];

}

// return sum

return sum;

}

// function to add values of 2-D array

int sumB(array_t a) {

// variable declaration

int i, j;

int sum = 0;

// traverse through columns

for (j = 0; j < N; j++)

// traverse through rows

for (i = 0; i < N; i++) {

// sum of elements

sum = sum + a[i][j];

}

// return sum

return sum;

}

// function to add values of 2-D array

int sumC(array_t a)

{

//variable declaration

int i,j;

int sum=0;

//traverse through columns

for(j=0;j<N;j+=2)

//traverse through rows

for(i=0;i<N;i+=2)

{

//sum of elements

sum+=(a[i][j]+a[i+1][j]+ a[i][j+1]+a[i+1][j+1]);

}

//return sum

return sum;

}

Blurred answer
Students have asked these similar questions
A 2-way set associative cache consists of four sets. Main memory contains 2K blocks of eight words each. Show the main memory address format that allows us to map addresses from main memory to cache. Be sure to include the fields as well as their sizes. Compute the hit ratio for a program that loops 6 times from locations 8 to 51 in main memory. You may leave the hit ratio in terms of a fraction. Please show details how you obtain the result.
Computer science Computer organization subject
A 2-way set-associative cache consists of four sets. Main memory contains 2K blocks of 8 bytes each and byte addressing is used.Q.) Compute the hit ratio for a program that loops three times from addresses 0x8 to 0x33 in main memory. You may leave the hit ratio in terms of a fraction.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education