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

Ie1005-W2t1 ZX

This document contains notes for a C programming tutorial session covering: 1) An introduction to the first C program "Hello World" including how to write, compile, and run a basic C program. 2) An explanation of integrated development environments like CodeBlocks and how to use its features to write, build, and run C programs. 3) Hands-on examples of printing output with printf and getting input with scanf. 4) A discussion of syntax, logical, and runtime errors in C programs.

Uploaded by

William W
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)
94 views

Ie1005-W2t1 ZX

This document contains notes for a C programming tutorial session covering: 1) An introduction to the first C program "Hello World" including how to write, compile, and run a basic C program. 2) An explanation of integrated development environments like CodeBlocks and how to use its features to write, build, and run C programs. 3) Hands-on examples of printing output with printf and getting input with scanf. 4) A discussion of syntax, logical, and runtime errors in C programs.

Uploaded by

William W
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
You are on page 1/ 8

2023_24(S1) – IE1005 – Week2/Tut-1

Date 22 Aug 2023 Tuesday Tutor: Dr ZHOU Xing (ZX)


12:30am-2:30pm Office/Phone: S1-B1c-95 (x4532)
Email: [email protected]
Class EE22 TA: QIAO ZHONGZHENG
Email: [email protected]

Note to students:
1) Please sign your attendance
2) Please sit according to the S/N on attendance sheet
corresponding to the PC number, and sit on the same
seat throughout the course
3) Attend your registered class only (not other classes)
4) Understand the goal of learning the C programming
language, and appreciate various “balances” [knowledge/
skills vs. marks/CAs; given tutorials vs. extra reading/practice]
5) Learn the language capabilities and programming skills
6) Practice, practice, and practice – make best use of lab
time, and adjust your own pace [balance with class pace]
7) Come prepared before lab, and test your ideas/doubts
by asking “what-if” and practicing “trial-and-error”
8) It is extremely important to follow the lecture video
watching schedule
9) You will be given my Notes (but not tutorial slides)
 I won’t set any office hours but you can see me any time
as long as I’m in office. Email me when you have any
questions/doubts.

1
2023_24(S1) – IE1005 – Week2/Tut-1

2
2023_24(S1) – IE1005 – Week2/Tut-1

Assessment Components
1) Class Participation (10%)
 Answer tutorial questions in class, pro-active participation
 Work on practical exercises in class, raising questions & extending ideas
2) Continuous Assessment [CA] (20%): Two continuous assessments in
class (10% each)
 First continuous assessment [CA-1] planned for Week 5 (30min)
 Second continuous assessment [CA-2] planned for Week 9 (30min)
 Format: 1 question, programming-based, OPEN-book, you may discuss
and access internet but no copying from each other
 Submission on time: between 30min and 40min (10 to 0 mark)
3) Practical Test [PT] (40%): Two practical tests in class (20% each)
 First practical test [PT-1] occurs in Week 7 (45min)
 Second practical test [PT-2] occurs in Week 11 (45min)
 Format: 1 question, programming-based, restricted OPEN-book, no
access to internet except for NTULearn and softcopies of course
materials/notes; independent, i.e., no discussion, but you can consult
the tutor for assistance (10 to 0 mark)
 Submission on time: between 45min and 60min (10 to 0 mark)
 Coverage [PT-2]: Lecture lessons 1 to 9 (up to Modular Programming;
Tutorial/Practical lessons 1 to 9, excluding Pointers)
4) Common Quiz (30%): in week 14, CLOSED-book, Multiple-choice
questions, cover ALL contents including Arrays (weeks 12–13 topics). More
details from course coordinator

Tips:
 Concentrate on learning objectives, and reward (‘marks’) would come
along as a result
 Learn examples in the lab session and try to extend similar ideas in future
labs (and future career)
 Test your ideas by trial-and-error - test run C programs whenever in doubt
 Make a note of the mistakes so that you won’t repeat them
3
2023_24(S1) – IE1005 – Week2/Tut-1

Tutorial and Hands-on 1 (Week 2)


The first C program:
[Brian W. Kernighan & Dennis M. Ritchie]

 Create a text file named, say, hello.c:


#include <stdio.h>
main()
{
printf("hello, world\n");
}

#include <stdio.h> include information about


standard library
main() define a function named main
that receives no argument
values
{ statements of main are
enclosed in braces
printf("hello, world\n");
main calls library function
printf to print this sequence
of characters; \n represents
the newline character
}

4
2023_24(S1) – IE1005 – Week2/Tut-1

 Under UNIX/Linux systems, compile the C program by running


‘cc’:
cc hello.c

 The compiler also links any library (object files) used in the C
source code.
 An executable file with a default name ‘a.out’ will be generated if
no syntax errors.
 Run (execute) the C program by typing:
a.out

 It will print (on screen):


hello, world

Under CodeBlocks (IDE), text editor, compiler, linker, debugger,


etc, are all integrated within one GUI.
 Always do your coding in the Documents folder
 Save your C source file first before editing texts (so that the ‘smart’
C text editor will prompt you in C context with different colours).
E.g., ‘New file’ => rename ‘Untitled1’ to ‘myfile.c’
 C filenames are case-sensitive, cannot contain spaces, and must end
with ‘.c’ (lower-case ‘c’)
 ‘Build’ = ‘Compile + Link’. After any changes to the C source
code, it must be re-compiled/linked (re-built) before Running the
program; otherwise, you’d be running the previously compiled
program (inconsistent!)
 ‘Run’ = Executing/running the most recently compiled program
 ‘Build and Run’ = ‘Compile/Link + Run’. So, it is advisable to
always use ‘Build & Run’
 In the “Build log” tag, look for compiling/linking error/warning
messages, and debug accordingly
 Avoid using ‘smart’ “quotes”, use plain quotes: " and '
5
2023_24(S1) – IE1005 – Week2/Tut-1

Hands-on programming:

#include <stdio.h>
void main()
{
printf("hello, world\n");
//printf("hello, world");
//printf("hello, ");
//printf("world");
//printf("\n");
// printf("hello, world
// ");
}

6
2023_24(S1) – IE1005 – Week2/Tut-1

Advanced Practice (extra) – communicating with computer:


input from keyboard (scanf) / output to monitor (printf):

#include <stdio.h> // declare printf(), scanf()


void main()
{
int a; // declare variable a of type int
printf("Enter an integer: "); // prompt (why?)
scanf("%d", &a); // "hook" (address of)
printf("Value is: %d\n", a);
}

7
2023_24(S1) – IE1005 – Week2/Tut-1

Advanced Practice (extra):


Syntax/Logical/Runtime errors:

#include <stdio.h>
int main()
{
int a;

printf("Enter integer a: ");


scanf("%d", &a);
if (a==0)
printf("Divide by 0.\n");
else
printf("1/a = %f\n", 1.0/a);

return 0;
}

Some ‘food for thought’ (to be elaborated on


“computational thinking” in future weeks)
Q: Find the sum of the following number series:
1 + 2 + 3 + … + 10

And, to be generalized…
8

You might also like