Arrays as Function Arguments

Arrays as Function Arguments - Generate: takes an array and...

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

View Full Document Right Arrow Icon
Arrays as Function Arguments Sending arrays to functions as formal parameters Pass not only the array but send a parameter To pass an array to a function, it is common to pass array size so that function knows how many elements to process: o NAME (pass this array, ARRAY_SIZE); Array size must also be reflected in prototype, header: o Void NAME (int [], int); prototype o Void NAME (int [], int size); header Passing a file as a parameter to a sub function fstream inFile Programming Project 4 Prime number: any number greater than one divisible only by 1 and that number Use the array question from exam 2 in this project to compute prime numbers in function 1
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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Generate: takes an array and a number It should give you all the prime numbers int another [1000]; use a for loop to change the contents of the array use another for loop j = 0 size = 0 for ( i=0, i < n-1, i++) if primes [j] = another ; size ++ j ++ after this loop the array will contain the prime numbers and the size + + will tell you how many prime numbers you filled Boolean function: String array: Sum Array: Int sumArray (const int array , int numterms); Int sum = 0, I; For (i=0, i<numterms, i++) Sum = sum + array [i]; Return sum;...
View Full Document

Page1 / 2

Arrays as Function Arguments - Generate: takes an array and...

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

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