0% found this document useful (0 votes)
19 views

Table of Contents: Lab 1: Getting Started 2 1.1 B 2 1.2 F H W !' 5 1.3 G E 7

This document provides instructions for completing guided exercises and an assignment in an introductory programming course. It teaches the basics of programming in C including how to print text, save and run programs. The guided exercises have students print their name and a tic-tac-toe board. The assignment requires printing initials. Students are instructed to save and upload four programs to an online platform for submission and grading.

Uploaded by

asyrafabdullah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Table of Contents: Lab 1: Getting Started 2 1.1 B 2 1.2 F H W !' 5 1.3 G E 7

This document provides instructions for completing guided exercises and an assignment in an introductory programming course. It teaches the basics of programming in C including how to print text, save and run programs. The guided exercises have students print their name and a tic-tac-toe board. The assignment requires printing initials. Students are instructed to save and upload four programs to an online platform for submission and grading.

Uploaded by

asyrafabdullah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Table

of Contents

LAB 1: GETTING STARTED 2


1.1 BASICS 2
1.2 FIRST CODE ‘HELLO WORLD!’ 5
1.3 GUIDED EXERCISES 7
1.3.1 PRINTING OUT YOUR NAME 7
1.3.2 PRINTING A TIC-TAC-TOE BOARD GAME 8
1.4 ASSIGNMENT 1: PRINTING YOUR INITIALS 10
1.5 UPLOADING YOUR PROGRAMS IN KALAM 10


Lab 1: Getting started
At the end of this lab, please upload the following codes in KALAM:

1. The Hello World Code in Section 1.2: program1.c


2. Print out your name code and hobby in Section 1.3.1: lab1ex1.c
3. Print out a tic tac toe board game: labex2.c
4. Print your initials: assignment1.c

1.1 Basics
This section will teach you how the basics and fundamentals of programming, which you will apply
for the rest of the course.

Step 1: Double click on the icon on the Desktop


Step 2: You will see this screen pop out


Step 3: Open a new file (File -> New). A blank file will appear


Step 4: An empty file will pop out as below


Step 5: Save the file as *.c (example: program1.c or example1.c): File -> Save As -> program1.c


Step 7: You will see the filename you have previously saved at the top left corner (see below)

Step 8: When writing any code, you MUST start by writing the following 4 lines:


Note that the content of your code will be written in the red box (see below):

Write your code


here


Step 9: Commenting is a good practice in programming.

• Comments start with /* and terminated with */.


• You may write anything in between.
• Comments are for the programmers eyes and not for the computer to read.
• Always start your code with the following comments:
o Your name and student ID – see Line 1 below
o Name and summary of what your code does – see Line 2 below

1.2 First code ‘Hello World!’
This section will teach you how to print out to the output screen using the printf() function.

Step 1: To use the printf() function, type out as seen below in Line 7:


Step 2: To print out Hello World!, simply append to the printf() function by typing out “Hello World!”
as below (see Line 7):


Step 3: Run the code to see the output

1. To Run

Editing
Pane


2. Output
Output

Pane


In short, whatever that is written between “…” in the printf() function in the editing pane:

Text to print out

Will be printed out in the output pane:


Text output

Step 4: Note that the output comes out in a single sentence ‘Hello World!>Exit code: 0’.
To push the words ‘>Exit code: 0’ to a new line (the equivalent of an ‘Enter’ when typing in a
word document), add ‘\n’ before the closing ” in the printf() function as follows:


Add \n for new line

Upon running the code, the following will be printed out in the output pane:

new line


1.3 Guided Exercises
1.3.1 Printing out your name
For this exercise, write a code that prints out your name and save the code as lab1ex1.c

Instructions:

1. Open a new *.c file and call it lab1ex1.c: follow instructions in Section 1.1 Steps 3-7
2. Type out the basic code: follow instructions in Section 1.1 Step 8-9
3. Tell the code to print your name: see (1. Edit text to print) in figure below
4. To run the code: see (2. Run the code) in figure below

For example, if your name is Ali Yusuf bin Muhammad then you want to print the output “My name
is Ali Yusuf bin Muhammad!” like the following:

2. Run the code

1. Edit text to print

3. Output


5. Now include your hobby (see figure below)
6. Run the code

There are two ways of writing the code:

Both of the codes will produce the following output:

1.3.2 Printing a tic-tac-toe board game


Though it seems that everything you have done up to now, is pretty basic, but it already sufficient
for you to come up with a (medieval) tic-tac-toe board game (or any simple board game for that
matter!)

Write a tic-tac-toe program and call it labex2.c that looks like the following:

Run the code to see the following output:


You may also edit the code to put circles and crosses:



1.4 Assignment 1: Printing your initials
Print out your initials and upload the code as Assignment1a.c

For example,

1. If your name is Muhammad Taib Bin Ali


2. Thus your initials are: MTA
3. Write a program to produce the following in the output pane

1.5 Uploading your programs in KALAM


1. Open your KALAM account and access the subject page: BMM1312
2. Under Week 1, you will see a submission link like below:

You might also like