Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

PROBLEM 1:

for (i=0; i<numrows; i++) for (j=0; j<numcols; j++); pixels++;

PROBLEM 2:
int minval(int *A, int n) { int currmin; for (int i=0; i<n; i++) if (A[i] < currmin) currmin = A[i]; return currmin; }

PROBLEM 3:
int minval(int *A, int n) { int currmin = MAXINT; for (int i=0; i<n; i++) if (A[i] > currmin) currmin = A[i]; return currmin; }

PROBLEM 4:
switch (i) { case 1: do_something(1); case 2: do_something(2); case 3: do_something(1); case 4: do_something(4); default: break; } break; break; break; break;

PROBLEM 5:
if (foo = 5) foo == 7;

PROBLEM 6:

int i = 5; int j; int foo(int j) { for (i=0; i<j; i++) do_nothing(); return j; } void ineedj(void) { cout << "j is " << j << "\n"; } main() { int j; j = foo(i); ineedj(); }

PROBLEM 7:
// random returns a random (positive) integer. // Random returns a random integer in the range 0 to n-1. #define Random(n) random()%n

val = Random(j-i+1);

PROBLEM 8:
char* string1 = "Hello"; char* string2 = "World"; if (string1 == string2) do_something();

PROBLEM 9:
// Return pointer to the node storing "val" if any; NULL otherwise void find(listnode **curr, val) { while (*curr != NULL) if (*curr->val == val) return; else *curr = *curr->next; }

PROBLEM 10:
char string1[10] = "Hello"; char string2[10]; strcpy(string1, string2);

PROBLEM 11:
char string[4]; for (i=0; i<4; i++) string[i]=getchar(); cout << string;

PROBLEM 12:
int i; char string[5] = "hello"; int j;

PROBLEM 13:
char* ptr; cin >> ptr;

PROBLEM 14:
int i; int array[5]; int j; for (i=0; i<=5; i++) cin >> array[i];

PROBLEM 15:
// Delete the node following the one that ptr is pointing at. void del_link(lnode* ptr) { ptr->next = ptr->next->next; }

PROBLEM 16:
char *initialize() { char string[80]; char* ptr = string; return ptr; } main() { char *myval = initialize(); do_something_with(myval); }

PROBLEM 17:
char* assign() { return "hello world!"; } main() { char *ptr = assign(); }

PROBLEM 18:
// Insert a value into an ordered linked list void insert(lnode*& curr, int val) { if (curr == NULL) curr = new lnode(val, NULL); else if (lnode->val > val) curr = new lnode(val, curr->next); else { curr = curr->next; insert(curr, val); } }

PROBLEM 19:
main() { Record city; lnode *list = NULL; while (data_to_read()) { Readin_data(&city); insert(&city, &list); } } void insert(Record*& city, lnode*& list) { lnode* ptr = new lnode; ptr->next = list; list = ptr; prt->data = city; }

You might also like