You are suggested to use the teaching servers hulk.soic.indiana.edu or tank.soic.indiana.edu for practicing C programs.

1.Basic statement in C

1.1 loop

Example: a simple loop program : code

Something worthy further discussion:

overflow of int variable

When you declared a signed int variable, for example, in some old machine, it takes up 8 bytes.
[][][][][][][][]
In this case, the first bit is used to indicate whether the digital you save in this variable is positive or negative.
0: positive
1:negative
And the range of integal number it can hold is [255,-256].
So when you continue adding up to this variable, for example, add 1 to 255 (which is 01111111 in machine code). In mathematics, it will be 256, but in machine code, it's 11111111, which turns out to be -256. "Overflow!" code


1.2 If-Else

Make decision among multiple choices using if-else structure. For example, input score of some course and get the corresponding grade: A: 90-100 B: 75-89 C: 60-74 F: 0-59.

sample code

1.3 I/O operation

Read carefully C manual for the following functions in stdio.h & stdlib.h
fopen fclose
fwrite fread
fputc fgetc fgets
fscanf fprintf
getc getchar gets getline

Here is a sample program which allows you to open a file and write a sentence into it.Code

2. Some simple algorithm

First algorithm: find out the minimum value among a bunch of numbers:

Pseudo code:
        int min = &infin /* in real code, you could assign a very large number to min*/
        for a in array /*array stores the numbers you input*/
            if a < min
                min = a
        print min