Tom Kelliher, CS23
Feb. 9, 1996
From last time:
Determine the loop invariant for a function which finds the sum of the first five positive values in an integer array with n elements.
Starting with a function:
int sumFive(int array[], int n) { int count; // # of positive elements found int i; // loop counter int sum // sum of positive elements // invariant: sum is the sum of the count positive values among // the elements array[0]...array[i-1]. // 0 <= i < n, 0 <= count <= 5 for (count = i = sum = 0; i < n && count < 5; i++) if (array[i] >= 0) { count++; sum += array[i]; } if (count == 5) return sum; else return -1; // neat trick, right? }
Unix RULZ!!!!!!!
Unix is easy to use but difficult to learn.
It is impossible to learn everything about Unix. Concentrate on what you need and what you think you will enjoy. Start by learning the basics. Then learn whatever you want, in whatever order you want.
Unix is a culture. Unix is a set of tools.
I hear, and I forget. I see, and I remember. I do, and I understand.
ls -a -C -F kelliher/pub
ls -l ~
cat Class/Cs23/Hw/hw1.tex
w | grep burgerec
g++ -o homework1 homework1.cc library.cc
./homework1 > homework1.results
rm *
rm -i *
alias rm 'rm -i'
less .cshrc .login