Sample C Programs for CS 2073
Here are some of the programs presented in class.
- balance.c
- Check for balanced curly braces in a C program.
- cat.c
- Print the file named on the command line to standard output.
- countprimes.c
- Print the number of primes from 2 through argv[1].
- fact.c
- Program to print factorials of 0 through 13 using a function.
- fib.c
- Program to print the first 21 Fibonacci numbers using a function.
- findstring.c
- Program that prints all occurences of string in the the first
command line argument in the file named by the second command line argument.
- funcs.c
- Examples of using void functions.
- max.c
- Program to print the maximum number in a file called numbers.
- reverse.c
- Read in a string and print it backwards, using a void function.
- sd.c
- Find the mean and standard deviation of numbers in a file
called numbers
- sd2.c
- Find the mean and standard deviation of numbers in a file
called numbers, using an array and functions.
- search-sort.c
- Do timings on linear search, binary search, insertion sort, and
qsort (a version of quick sort).
- sieve.c
- Sieve of Erasthones: print out prime numbers from 2 through 1000
by sieving out the composites.
- string.c
- Use a function to print the value of the first decimal integer
in a string, without using scanf().
- strip.c
- Strip the comments from a C program named on the command line.
- students.c
- Read in a list of students IDs and scores, giving the weighted
average for each student and the average for the best student.
- fsa.c
- Read in a description of a Finite State Automaton, and then check
to see if the string on the standard input is accepted.
- circle.c
- Draw circles on the screen using 2D arrays
- matrix.c and
matrix.h
- An abstract data type using typedef and struct
that implements a matrix data type with bounds checking.
- wordfreq.c
- A program that prints the twenty most frequent words in the
file on the standard input. Try it on William Shakespeare's
King Henry VIII (or just read the play
if you're bored with computer science :-).
- life.c
- The Game of Life - A program that uses two-dimensional arrays to
simulate the life of a colony of cells. Use the following
initial configuration files: shapes and random as the first command like argument to watch the
game of life play out. See the source code for more details.
- bubble.c - Bubble sort
- numprimes.c - Count prime numbers using
methods from the lecture notes