12_ArraysB(Oct.21) - APSC160 Arrays B Oct.21-2010 Q4

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
APSC160 Arrays B Oct.21-2010 s search function*/ /* * Determine how many duplicate integers are found in two * arrays, each of which is filled with unique elements. * For example, if the value 99 appears in array1 AND * in array2, then add one to the count of the number of * elements found in both arrays. * * Author: Ed Knorr * Date: October 21, 2010 * Lab Section: L1X * * Version: 1 (one function calls another; no nested loops) */ #include <stdio.h> #include <stdlib.h> /* here are the sizes of the arrays I'm using */ #define SIZEA 5 #define SIZEB 6 #define SIZEC 3 #define SIZED 3 /* declare function prototypes */ int compare_arrays( int array1[ ], int size1, int array2[ ], int size2 ); int search( int array[ ], int size, int toFind ); int main( void ) { int num_duplicates; /* here are the arrays I'm using */ int arrayA[ ] = { 3, 6, 1, 2, -4 }; int arrayB[ ] = { 7, 9 -1, 2, 6, 8 }; int arrayC[ ] = { 4, 7, 11 }; int arrayD[ ] = { -1, 3, 12 }; num_duplicates = compare_arrays( arrayA, SIZEA, arrayB, SIZEB ); printf( "We found %d duplicates in the arrays\n", num_duplicates ); num_duplicates = compare_arrays( arrayC, SIZEC, arrayD, SIZED ); printf( "We found %d duplicates in the arrays\n", num_duplicates );
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/12/2010 for the course APSC 160 APSC 160 taught by Professor Charles during the Spring '10 term at The University of British Columbia.

Page1 / 7

12_ArraysB(Oct.21) - APSC160 Arrays B Oct.21-2010 Q4

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online