User:CharmlessCoin/C problems

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

A Taste of C
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

 * 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 [//en.wikipedia.org/wiki/Exponentiation#Efficient_computation_of_integer_powers 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, $$\sum_{i = 0}^{100}i = (1 + 2 + 3 + 4 + ... + 100).$$

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 $$i$$) is the value added to the overall sum.

How one could in general define this formula would be $$f(i, k) = \sum_{i = i}^{k}i = (i + \underbrace{(i + 1) + (i + 2) + ...}_{\text{While }i \leq k})$$. 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:

$${1 \over 2} = {1 \over 2}$$ 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:

$$ \begin{align} {1 \over 2} = {1 \over 2} \\

1 \times {1 \over 2} = {1 \over 2} \\

1 \times 1 \times {1 \over 2} = {1 \over 2} \\

1 \times 1 \times 1 \times {1 \over 2} = {1 \over 2} \\ ... \\ \end{align} $$

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  where 6 is the number of spaces printed for a tab.