C By Discovery (4th Edition)

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

View Full Document Right Arrow Icon
CSE 1320 – Section 001 Midterm 3 – Final Exam – Practice B Name:_____________________________________________________Grade: ___________ [100pts] 1. Given a nom-empty set A of numbers implemented as an array of sorted non-unique integers (ascending order) with n elements, write a C function void unique(int *A, int n, int **U, int *s), which computes a set U with the sorted unique integer elements (ascending order) with s elements of the original set A. Note that memory must be allocated for the set U. void unique(int *A, int n, int **U, int *s) { int i, count = 1; for (i=1; i<n; i++) if (A[i] != A[i-1]) count++; *s = count; *U = (int *) malloc(count*sizeof(int)); (*U)[0] = A[0]; count = 1; for (i=1; i<n; i++) if (A[i] != A[i-1]) { (*U)[count] = A[i]; count++; } } 2. Write a C function void print_zigzag(int **A, int nr, int nc) that prints a two-dimensional array A with nr rows and nc columns in zigzag order in a single line. For example, the 2D array below is printed as: “ ABCDEJIHGFKLMNOTSRQPUVXYZ ”. Z Y X V U T S R Q P O N M L K J I H G F E D C B A void print_zigzag(int **A, int nr, int nc) { int i, j; for (i=0; i<nr; i++) if (i % 2) { for (j=0; j<nc; j++) printf(“%c”, A[i][nc-j-1]); } else { for (j=0; j<nc; j++) printf(“%c”, A[i][j]); } printf(“\n”); }
Background image of page 1

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

View Full DocumentRight Arrow Icon
3. Given two strings str1 and str2, write a C function void alternate(char *str1, char *str2) to
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

Practice 3B - CSE 1320 Section 001 Midterm 3 Final Exam...

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

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