You are on page 1of 29

Introduction To C Language (Week 3&4)

By: Pn Wan Fazlini Idayu bt Wan Fakari

How computer working??

Data Processing Cycle (Kitaran Pemproses Data)

Data Processing Cycle


Data processing cycle is the process of converting of a data into a useful information. y The data is processed again and again until the accurate result is achieved. y 3 basic activities of data processing: (a) Input (b) Process (c) Output
y
3

(a) Input
y

A set of information called data will be entered into the computer from keyboard, floppy disk, hard disk etc. and stored in a portion of the computer memory. This input which is an input to the computer will then be processed to produced the desired result.

(b) Process
y

Data control and storing, numerical comparison and arithmetic handling being done to the input to get the output.

(c) Output
y

The processed data which produced certain result is known as the output. The output data will be presented in a sheet of paper through the printer or display on a monitor

Carta Alir
Simbol Makna Arah aliran Mula / Tamat Input/output Proses Pilihan Penghubung Offpage connector Predefined Process

Annotation
7

What you have learned so far .


y

Analysis: - Understand the problem Design: - How to develop solutions (Algorithm) - How flowchart works - How to construct flowcharts

The next step is coding


y

Coding is a process of converting flowchart to program code (source code) But, before you can start doing this, you should learn some basics including the language itself.

The conversion is almost straight forward


Example: multiplying two number void main () { printf("Enter the first number=> "); scanf("%d",&A); printf("Enter the second number=> "); scanf("%d",&B); C = A * B; printf("The Result is %d", C); } Display the result C The program still cannot be executed. It is not completed yet.
10

Start

Read A Read B

Calculate result C=A*B

Stop

You will get these errors

Error 1: Call to undefined function printf Were trying to call a function that is not recognized by the compiler.`

Error 3: Undefined symbol A Were trying to use a variable but it has never been defined. Compiler doesnt recognize it

11

Errors we found just now are called syntax errors. y Syntax means rules of a programming language y You will get syntax errors if you do not follow the rules
y

12

Fix the errors and complete the program


This statement will help the compiler to recognize function printf and function scanf Variable must be declared before we can use it

13

Structure of a C program

14

The greeting program

15

Comment
Comment is a statement that is not executed. y Compiler will ignore all comments in your program y It is used to describe part of your program; makes your program more readable. y This helps people and also yourself to understand your codes.
y
16

Examples of comments

17

Identifiers
A symbolic name of data, functions or other objects. OR y An Identifier is a name for a variable, type, type member, template, class, function, namespace etc and is usually limited to letters, digits and underscores.
y

E.g: main => symbolic name of main function printf => symbolic name of a function that prints output onto the screen Rules for identifiers: 1. First character must be alphabetic character or underscore 2. Must consist only alphabetic characters, digits, or underscores 3. First 31 characters of an identifier are significant 4. Cannot duplicate a reserved word
18

Example: Valid Names: a student8 student_name _person_name TRUE FALSE Invalid Names: $a 3name person name int what?

19

In C language, identifiers are case sensitive. Example: a is different from A.

20

Nyatakan sama ada pencam takrifan pengguna berikut sah atau tidak:
Pencam 1 Pencam_yang_terpanjang_sekali 23-JlnDuku Jalan#2 Kadar_Ke2 RM1200 $500 S100% Jalan_Duku BAB10 HEADLINE_TODAY MAIN void int
Tidak sah Sah Tidak sah Tidak sah Sah Sah Tidak sah Tidak sah Sah Sah Tidak Tidak Tidak Tidak

21

Standard data types

22

Integer types

23

FloatingFloating-point types

24

Some strings

25

Null characters and null strings

26

Formatted input and output

27

Format of printf statement

28

Format of scanf statement

29

You might also like