Sample Programs

C Programming (COP 2220)

This is an index to some sample C programs you will find instructive. Remember, the best way to learn a programming language is to study, modify, and execute existing programs.


  • Sentinel-controlled loop with accumulation: payroll.c
  • Compute weighted average: grader.c
  • Using switch and getchar: pqcount.c
  • Using switch, ASCII codes, "loop and a half": namenbr.c
  • Array fill, display, sum: sumArray.c
  • Date of Easter computation: easter.c
  • Determine if year is a leap year: isleap.c
  • Determine day-of-the-week: dowdemo.c
  • Determine number of days in a month: dinmdemo.c
  • Using the strtok function: token.c
  • Searching for substrings with strstr: strstr.c
  • Changing case of a string: chgcase.c
  • Arrays of pointers to strings: ex7-9.c (convert month number to month name)
  • Pointers to functions: order.c
  • A "Point" structure program
  • Obtaining filename to open interactively: filetest.c
  • Printing a file: printFile.c
  • Dynamic memory allocation: getMem.c
  • Direct-access file transaction program: fileTrans.c
  • This isn't really a C programming example, because it's written in MS QuickBasic, and was distributed as a source example with release 4.5. It does a good job providing a visual comparison of five different sorting algorithms: insertion, bubble, heap, shell, and quick. Run it in a command console window: sortdemo.exe
 Updated: 07.31.2009