0% found this document useful (0 votes)
13 views4 pages

C Programming Lab Guide for Beginners

This lab sheet introduces first-year Computer Science students to the Code::Blocks IDE for C programming. It outlines objectives, provides a step-by-step guide to creating and managing a C project, and includes exercises for students to practice coding and understand basic C syntax. The document also explains how to compile and run programs, as well as modify output using printf statements.

Uploaded by

aymenachoura2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

C Programming Lab Guide for Beginners

This lab sheet introduces first-year Computer Science students to the Code::Blocks IDE for C programming. It outlines objectives, provides a step-by-step guide to creating and managing a C project, and includes exercises for students to practice coding and understand basic C syntax. The document also explains how to compile and run programs, as well as modify output using printf statements.

Uploaded by

aymenachoura2006
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Faculty of MISM 2025/2026

Department of Computer Science Algorithmics and data structures 1


First year LMD Semester 1

Lab Sheet No 1. Getting started


1) Objectives
The objective of this first lab session is to familiarize yourself with the development
environment that will be used throughout this semester, namely the Code::Blocks
environment. In this lab session, you will learn how to create your first C program in
Code::Blocks, how to compile and execute it, and you will explore some basic
commands.
2) Presentation
Code::Blocks is an Integrated Development Environment (IDE) mainly designed for
programming in C and C++. The version of Code::Blocks that will be used during the
lab sessions is version 17.12.
3) Getting Started with Code::Blocks
3.1) Launching Code::Blocks
You can launch Code::Blocks 17.12 by clicking on the desktop icon or from the
Start Menu → All Programs → Code::Blocks.
3.2) Description of the Code::Blocks 17.12 Interface
When you click on the Code::Blocks 17.12 icon, the following interface will appear:

Figure 1

1st Year Computer Science – University of Guelma 1 Dr. Abderrahmane Kefali


3.3) Creating a project
To create a new project, follow these steps:
• Click on "Create a new project" in the main window, or go to the File menu → New
→ Project, or click the "New" button in the standard toolbar and select
"Project" from the drop-down menu.
• The "New from template" window opens (Figure 2) and prompts you to choose a
project template. Select "Console application" and click "Go."
• The dialog box that opens serves no purpose; check the box that says "Skip this
page next time" and click "Next >" to continue.
• The next window (Figure 3) will then ask you if you will be using C or C++. Select
C, and then click the "Next >" button.

Figure 2 Figure 3
• Now, you need to give your project a name and select the folder where it will be
saved. Enter the name in the "Project title" field, and then click the button to
browse for the directory where the project will be saved. Confirm by clicking the
"Next >" button. See Figure 4.
• Finally, the last window (Figure 5) allows you to choose the compiler (usually GNU
GCC by default) and then click the "Finish" button.

Figure 4 Figure 5
1st Year Computer Science – University of Guelma 2 Dr. Abderrahmane Kefali
• The project is now created, and it will appear in the current workspace on the left
side of the interface.
3.4) Editing the source file
• Expand the "Workspace" tree of projects located in the
"Projects" tab of the "Management Area" in Code::Blocks.
• Click on the  sign to the left of "Sources" to display the list Figure 6
of files in the project (Figure 6).
• Double-click on "main.c". It will be displayed in the central
editing window with C syntax highlighting. Now, it's ready to
be edited (Figure 7).

Figure 7
Saving and opening
• Don't forget to save your program after each modification by selecting the "Save
file" command from the "File" menu, clicking the button on the "Standard"
toolbar, or using the keyboard shortcut + .

• To open an existing project, go to the "File" menu and select the "Open..."
command or use the keyboard shortcut .
3.5) Compile and run

Code::Blocks has a "Build" menu and a "Compiler" toolbar


reserved for compilation and execution.
• To compile the project, simply click on the "Build" command in the "Build" menu,
or click the button in the "Compiler" toolbar, or use the keyboard shortcut
+ .
• You can start the running by clicking either the "Run" command in the "Build"
menu, or the button in the "Compiler" toolbar, or by using the keyboard
shortcut + .
• You can also compile and run (in one click) by clicking the "Build and Run"
command in the "Build" menu, or the button in the "Compiler" toolbar, or by
using the keyboard shortcut .
3.6) Exit Code::Blocs
You can exit Code::Blocks directly by clicking the button , or by choosing the
"Quit" action from the "File" menu, or by using the keyboard shortcut .

1st Year Computer Science – University of Guelma 3 Dr. Abderrahmane Kefali


4) Your first program in C with Code::Blocs
Create a new project and name it "First Project-<your name>" following the same
steps outlined in section 3.3. Then, open the "main.c" file by following the steps
described in section 3.4. The following program will be displayed:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}

1. Compile and run this program.


2. Modify the sentence "Hello world" to "Good morning, my name is <Your name>, I
am a student in 1st year Mathematics", then compile and run the program. What
do you notice? Deduce the role of printf.
3. Modify the program by adding "\n" and then "\t" after "Good morning," and re-
run it. What do you notice? Deduce the meaning of "\n" and "\t".
4. Now, make the necessary modifications to the program so that it displays " I am
a student" and "in 1st year Mathematics" each on a separate line.
5. Modify the program to display:
a) A filled rectangle of asterisks (Figure 8.a)
b) A right-angled triangle of asterisks (Figure 8.b)
c) An isosceles triangle of asterisks (Figure 8.c).
****** * *
****** ** ***
****** *** *****
****** **** ********
****** ***** **********
(a) (b) (c)
Figure 8
6. Delete all the printf statements in the program and replace them with:
printf("Your mark is %d/20",15).
7. Change 15 to 15.75. Compile and run the program. What do you notice?
8. Change "%d" to "%f", then compile and run.
9. Deduce the role of "%d" and "%f".

1st Year Computer Science – University of Guelma 4 Dr. Abderrahmane Kefali

You might also like