You are on page 1of 5

Lab Exercise (Chapter 1)

Exercise 1.
Familiarize with the C development environment:
a. MinGW
i. Download the MinGW portable from eLearn and install it on
your PC/Laptop.
ii. Use any text editor (e.g. Notepad) to create a file with
content below and save as helloworld.c in the bin folder of
MinGW that youve installed earlier

iii. Run the command prompt by typing cmd from your windows
iv. Go to the bin folder of MinGW and run command below:
gcc helloworld.c -o helloworld.exe
v. Notice it will create an executable program call
helloworld.exe. You can run the program that youve just
created by typing the program name (e.g. helloworld)
b. Microsoft Visual C++
i. Start the Microsoft Visual C++
ii. Create a new Win32 console empty project
iii. Create a new c program file with the same content as above
and save it as helloworld.c
iv. Run the program by clicking the menu option Debug->Start
without debugging
(Refer to the demo)
Step 1: Go to New->Project

Step 2: click on Win32, choose Win32 Console Application, then type


your project name you want to create (a project name can be
different from the .c file name)

Step 3: click next

Step 4: select Empty project, then click Finish

Step 5: Right click the Source files, click Add -> New Item, to add a
new .c file

Step 6: Choose C++ File (.cpp), and type your file a name and end
with .c extension. Then click Add. [IMPORTANT: For c program,

remember to end your file with .c extension, else default


will be .cpp]

Step 6: Done! Youre now ready to type your c program code.


Exercise 2.
Modify the program as below and run it. Notice if theres any
difference?

Modify the program as below and run it again. Notice if theres any
difference?

Note: Try out other escape sequence character: \n

\t

\a

\\

Exercise 3.
Create a simple calculator that can add two integers and
produce the output

Objective of this lab exercise:


1. Let student familiarize with the development environment and structure of
a simple C program.
2. Observe the various behavior of escape sequence character.
3. Learn the basic printf and scanf statement to get input from user and
send result to the output screen.

Notes to instructor:
1. Demo the usage of different development environment
2. Explain the simple structure of C program
3. Explain the usage of printf and scanf statement

You might also like