DAY16
Monday, 18 June 2012
Today we will talk about:
-
swapping, which interchanges the values of two variables.
-
sorting, which rearranges a set of values so that they have an order.
-
arrays, which allow you to set up, store, and compute with lists.
-
rules for declaring an array variable, for initializing, using, or
changing an entry in an array.
-
examples of how arrays are used to store mathematical vectors;
lists of grades; a sequence of Fibonacci numbers.
Programs and functions we might talk about:
-
abc_max.c sets the entries A, B, C
to random numbers (using iran.c), then finds the maximum.
-
abc_sort.c sets the entries A, B, C
to random numbers (using iran.c), then sorts them.
-
abc_swap.c uses the idea of swapping
to rearrange the entries A, B, C.
-
array_max.c sets the entries of
an array to random numbers (using iran.c), then finds the maximum.
-
array_sum.c shows how to compute the
sum of the elements of an (integer) array.
-
grades.c uses an array to store up to 100 grades.
It computes the average, and prints a summary of the grades by letter.
-
grades.txt a file containing 53 grades, followed
by a "-1" to signal the end. The grading program can read this data, if you
use a command like ./a.out < grades.txt.
-
iran.c returns random integers in some interval.
-
p7.1.c shows how the elements of an array
can be used in expresssions. (This is an example program from the book.)
-
p7.3.c computes an array whose entries are Fibonacci numbers:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ... (This is an example program from the book.)
-
vector.c considers three vectors in 3D space,
and finds their lengths, dot products, pairwise cosines and angles.
Last revised on 17 June 2012.