{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2__Questions_8

# 2__Questions_8 - PRE POST 4 Write a function that counts...

This preview shows pages 1–3. Sign up to view the full content.

CIS 15BG Questions Chapter 8 Arrays: Two Dimensional Arrays 1. Declare a 2D-array of integers, with 4 rows and 10 columns, and initialize all its elements to 0. Then assign 50 to the last element in the second from the last row and 99 to the first element in the second column. 2. Given the square two-dimensional array of integers shown below, what will be printed from the following program fragment? 50 11 12 13 20 80 22 23 30 31 25 33 40 41 42 10 for( r = 0; r < 4; r++ ) for( c = 0; c < 4; c++ ) if( r == c ) printf( %d , table[r][c] ); 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CIS 15BG Questions Chapter 8 Arrays: Two Dimensional Arrays 3. Rewrite the fragment of code in Exercise 3 as a function then call it from main. Define two parameters: the 2D-array, table , and its actual size, n . Also, give a simpler and more efficient algorithm. #include<stdio.h> #define MAX_SIZE 100 int main( void ) { int table[MAX_SIZE][MAX_SIZE] = { {50, 11, 12, 13}, {20, 80, 22, 23}, {30, 31, 25, 33}, {40, 41, 42, 10} }; int size = 4; return 0; } /*=================================================
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: PRE: POST: */ 4. Write a function that counts and replaces all negative elements in a two dimensional array of integers by 0 according to the requirements described below then call it from main. before after 2-3 21-2-3 24 10-11 32 13 20 1 22-23-12 21 24 10 32 13 20 1 22 CIS 15BG Questions Chapter 8 Arrays: Two Dimensional Arrays #include<stdio.h> #define MAX_ROW 200 #define MAX_COL 300 int main( void ) { int table[MAX_ROW][MAX_COL] = { {-3, 21, -2, -3, 24}, {10, -11, 32, 13, 0}, {20, 1, 22, -23, -12} }; int rows = 3; int cols = 5; return 0; } /*================================================= This function counts and sets all negative elements in a 2D-array to zero. PRE: table – a two dimensional array of integers rows – the actual number of rows cols – the actual number of columns POST: value returned – the counter of negative elements changed to 0 */ 3...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

2__Questions_8 - PRE POST 4 Write a function that counts...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online