COMP6112-Introduction To Algorithm & Programming - Tanpa Video

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

Introduction to Algorithm and C

Programming
Presented By: Novita Hanafiah, S.Kom., M.Sc.
Outline
Introduction to Algorithm & Programming
• Algorithm definition
• Pseudocode
• Introduction to C Programming language
– Input & Output in C
Algorithm Definition
• Algorithm is a procedure for solving a problem in terms of the
actions to be executed, and the order in which these actions are
to be executed

• Derived from the word algoris and ritmis. Introduced by Al-


Khowarizmi.

• In the programming domain, algorithm define as method that


consist of structured steps in problem solving using computer.
Algorithm
Development Steps
Representing Algorithm

• How to develop an algorithm?


We can use:
– Writing
Structure English and Pseudo-code.
– Drawing
Flow Chart
Pseudo-code Example
Example : Algorithm Class Average
Start
Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
Add one to the grade counter
Set the class average to the total divided by ten
Print the class average.
End
Pseudo-code
There is some basic operation in pseudo-code
Basic Computer Operation:
1. Input
2. Output
3. Compute
4. Storing value to an identifier (Store)
5. Compare
6. Repetition (Loop)
Flow Chart Example

Start

Input a,b,c

d = b^2 – 4ac

Y
d<0
T

x1=(-b+sqrt(d))/2a Print message


x2 =(-b-sqrt(d))/2a “Imaginary”

Print: x1, x2

Stop
INTRODUCTION TO C
PROGRAMMING
Why Using C
• Flexibility
Close to low level machine language yet easy to understand

• Portability
Used form micro computer to super computer

• A Well Known Programming Language


It is used in many forms of implementations such as O/S, scientific
application, business application, etc.

• Supported With a Large Number of Libraries


C Standard Library
When programming in C, you’ll typically use the following building blocks:

•C Standard Library Functions


Example:
- <math.h> : Mathematical Functions
- <stdio.h> : Input and Output
- <stdlib.h> : Utility Functions
- <string.h> : String Functions
- <time.h> : Time and Date Functions
•Functions you create yourself
•Functions other people have created and made available to you
C Sturcture
• C language is a structural programming language
• It consists of functions
• There is no separation between function and procedure (if you
are from Pascal language background)
• Each C program has one main function called main
• Program will be started from the first line of the main function
• C language is case sensitive
• Every statement should be ended with a semi-colon (;)
C Sturcture
main() main()
1. { 3. {
statements; statements;
} return(0);
}

void main() int main()


2. { 4. {
statements; statements;
} return(0);
}
START TO CODE
References
• Paul J. Dietel,Harvey M. Deitel,. 2010. C : how to program. PEAPH.
New Jersey. ISBN:978-0-13-705966-9 Chapter 3, 9.
• Programming in C: http:// www.cs.cf.ac.uk/Dave/C/
• C Language Tutorial:
http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basic
s/
• Pseudocode Examples:
http://www.unf.edu/~broggio/cop2221/2221pseu.htm
• Computer & Internet Help : Understanding Flowchart Symbols:
http://www.youtube.com/watch?v=xLoL7tlJYws
• Reading from and Writing to Standard I/O:
http://aelinik.free.fr/c/ch05.htm
• Intro to File Input/Output in C:
http://www.cs.bu.edu/teaching/c/file-io/intro/

You might also like