User:CharmlessCoin/C problems

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The "featured" C book is missing a lot. Mainly practice problems. Here are a few that will hopefully spawn more.

A Taste of C[edit | edit source]

While the program shown here is very basic, much can be learned from experimenting with it. Try taking things out and adding extra things to see what happens!


General Practice[edit | edit source]

  • Write a program to remove all comments from a C program. (straight from K&R, probably a cool idea to change it into reading and writing to a file as well)
  • Look into this page on the computation of exponents. Now try to implement this in C.
  • Summation is the process of computing the sum of a sequence of numbers. As an example both on the idea and the notation,

To explain it, the bottom number is the beginning number of the sequence or the "lower limit", the top number is the "upper limit", or where the sequence will stop. The equation to the right (in this case ) is the value added to the overall sum.

How one could in general define this formula would be . Is it possible to implement this sort of thing in C?

  • Write a program using loops that prints out the following triangle:
   *
   * *
   * * *
   * * * *
   * * * * *
   * * * *
   * * *
   * *
   *
  • An interesting mathematical idea is infinite fractions. Take this for example:

One thing that you may or may not know, is that dividing by a number is the same as multiplying by its reciprocal (the inverse of the number/fraction).

To demonstrate both that idea, and infinite fractions let's reexamine the previous statement:

Looking at it, can you think of a way to implement this process in C?

  • Reading from standard input, write a program to translate tab characters to spaces. Allow it to be modified so as to allow detab -n 6 where 6 is the number of spaces printed for a tab.