Module 1: Running The C Program Using Code::Blocks
Module 1: Running The C Program Using Code::Blocks
OBJECTIVES
1. To enter the C source code, compile, and run the C program using CodeBlocks
software.
2. To identify the C program structure.
3. To load, edit and recompile the C program.
EXERCISE 1
Figure 1.1
a. Click File icon > New > Empty File (you are now in the text editor).
Figure 1.2
c. Type code program as below:
1 // Program 1(a)
2
3 #include <stdio.h>
4
5 int main (void) {
6 printf(“Hello World!”);
7 return 0;
8 }
a. Click File icon > Save file as.. > place your save file in Local Disk D > Create
Folder
b. Save the file as welcome.c. Type welcome.c in the box besides the Name
location.
OR
if you want to save in a specified folder, select the folder in the save as dialog
box.
3 EET110 BASIC COMPUTER PROGRAMMING MODULE 1
(e.g. /home/student/foldername), double click the folder icon and then type
welcome.c in the box besides the Name location. Click Save button.
Notes: The filename must be in one word with extension “.c”, for example
Program.c or pgm_1.c.
Figure 1.3
5. Steps to Run and Build a Program:
b. Command prompt will pop out and display the result of your program.
Figure 1.4
4 EET110 BASIC COMPUTER PROGRAMMING MODULE 1
d. If there are syntax errors, an error message will be displayed in the Compiler
section, and the programmer will edit the code with errors and recompile the
program until successful.
Figure 1.5
5 EET110 BASIC COMPUTER PROGRAMMING MODULE 1
EXERCISE 2
Practice to load existing C source file, edit the content and compile it.
Figure 1.6
b. Set the appropriate File location in Look in the field and select the appropriate
file name to be open.
c. Change and add a new line of code:
1 // Program 1(b)
2
3 #include <stdio.h>
4
5 int main (void) {
6 printf(“Hello World!\n”);
7 printf(“Welcome to UniMAP”);
8 return 0;
9 }
EXERCISE 3
f. Line 8 is the return statement that the control of the program to the operating
system. It also determines the value of the return type that matches the main
function.
g. Line 9 is a close brace “}” that marks the end of the body of main.
Type, save, compile, and run Program 1(c) above. What will be the output of
the program for the given input?
8
9 workDays = 5;
10 workHour = 6.5;
11 payrate = 20.50;
12
13 weeklyPay = workDays * workHour * payrate;
14
15 printf(“Weekly Pay : %f”, weeklyPay);
16
17 return 0;
18 }
Type, save, compile, and run Program 1(d) above. What will be the output of
the program for the given input?