|
META TOPICPARENT |
name="CourseExercises" |
Exercises 2: C Programming
Goal: |
|
Have a look at these examples, compile them and test them. Make sure you understand every little detail. If you don't: ask! |
|
> > | Type at least a few of them yourself using the text editor. |
| The compile command is
gcc -o hello hello.c |
| if the source code is in a file called hello.c The binary output file will be called hello and you can execute it with ./hello.
Exercise 2: Hello World! |
|
< < | The first program to be written in C is traditionally the “Hello World!” program. We don’t want to change this tradition and you are therefore asked to write the program that prints “Hello World!”. First compile it with the gcc command, then write a Makefile to build the program using the make command. |
> > | The first program to be written in C is traditionally the “Hello World!” program. We don’t want to change this tradition and you are therefore asked to write the program that prints “Hello World!”. Create a directory hello in ~/exercises/solutions/exercise_2 and create the source file hello.c in there. Compile it with the gcc command and run the program to test it (./hello). What does the dot do? |
| Exercise 3: A calculator
We want to produce a calculator program capable of calculating the 4 basic calculations: |
|
|
|
< < |
META FILEATTACHMENT |
attachment="codeExamples.tar.gz" attr="" comment="" date="1504866315" name="codeExamples.tar.gz" path="codeExamples.tar.gz" size="3240" user="uli" version="1" |
META FILEATTACHMENT |
attachment="exercises_2.odt" attr="" comment="" date="1505471107" name="exercises_2.odt" path="exercises_2.odt" size="21017" user="uli" version="1" |
|
> > |
META FILEATTACHMENT |
attachment="exercises_2.odt" attr="" comment="" date="1505762906" name="exercises_2.odt" path="exercises_2.odt" size="21198" user="uli" version="1" |
META FILEATTACHMENT |
attachment="newCodeExamples.tar.gz" attr="" comment="" date="1505765608" name="newCodeExamples.tar.gz" path="newCodeExamples.tar.gz" size="13591" user="uli" version="1" |
|