This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: /* finds the first negative number in array a. * If such number exists in a, the function returns 1 * and stores its value at address negative. * If such number does not exist, returns 0. */ int find_negative(int *a, int n, int *negative); You don’t need to write the read array function; just write the ﬁnd negative and main functions. Answer: 1 int find_negative(int *a, int n, int *negative) { int found = 0, i; for (i = 0; i < n && !found ; i++) if (a[i] < 0) { found = 1; *negative = a[i]; } return found; } int main() { int a[N]; int n=read_array(a); int negative; int found = find_negative(a,n,&negative); if (found) printf("First negative: %d\n", negative); else printf("No negative.\n"); return 0; } 2...
View
Full
Document
This note was uploaded on 01/14/2012 for the course CGS 3460 taught by Professor Staff during the Summer '08 term at University of Florida.
 Summer '08
 Staff

Click to edit the document details