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

02_Decision_Looping_ Arrays

The document covers fundamental concepts in C programming, focusing on arrays, decision-making, and looping structures. It explains how to declare and use arrays, the syntax for decision statements like if-else and switch, and various looping techniques including for, while, and do-while loops. Additionally, it highlights key keywords related to looping in C.

Uploaded by

viktornguyen1110
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 views

02_Decision_Looping_ Arrays

The document covers fundamental concepts in C programming, focusing on arrays, decision-making, and looping structures. It explains how to declare and use arrays, the syntax for decision statements like if-else and switch, and various looping techniques including for, while, and do-while loops. Additionally, it highlights key keywords related to looping in C.

Uploaded by

viktornguyen1110
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/ 40

C programming

Arrays, Decision and Looping

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 1


Lesson Objectives

▪ Introduce
▪ Array in C
▪ Decision in C
▪ Looping In C

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 2


Section 1
INTRODUCE

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 3


Section 2
ARRAY IN C

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 4


Array in C. Agenda

▪ What is Array?
▪ Multidimensional Arrays
▪ Array in memory
▪ How to declare an Array?
▪ How works with array?
▪ When will using Array?

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 5


What is Array?

▪ Each member of an array is identified by unique index or


subscript assigned to it
▪ The dimension of an array is determined by the number of
indices needed to uniquely identify each element
▪ An index is a positive integer enclosed in [ ] placed
immediately after the array name
▪ An index holds integer values starting with zero
▪ An array with 11 elements will look like -

Player[0], player[1], player[2],…. Player[10]

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 6


Multidimensional Arrays

▪ The simplest and the most commonly used multi-


dimensional array is the two - dimensional array
▪ A two-dimensional array can be thought of as an array of
two single dimensional arrays
▪ A two-dimensional array looks like a railway time-table
consisting of rows and columns
▪ A two–dimensional array is declared as -
int temp[4][3];

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 7


Array in memory

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 8


How to declare an Array?

An array is defined in the same way as a variable is defined.


The only change is that the array name is followed by one
or more
expressions, enclosed within square brackets [], specifying
the array dimension.

Storage_Class data_types array_name[size]


int player[11];

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 9


How works with array?

▪ Array elements and index


▪ Insert
▪ Find
▪ String
▪ Sort
▪ Delete

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 10


Array in C

When will using Array?

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 11


Array in C: Sumary

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 12


Section 3

DECISION IN C

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 13


Decision in C. Agenda

▪ Introduce
▪ How to build an expression?
▪ if, else… statement
▪ switch… statement

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 14


Introduce

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 15


How to build an expression?

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 16


if, else… statement

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 17


if, else… statement

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 18


switch… statement

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 19


switch… statement

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 20


switch… statement

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 21


Decision in C. Summary

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 22


Section 4

LOOPING IN C

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 23


Looping In C. Agenda

▪ What is looping in C?
▪ Syntax
▪ Enter and exit, break looping follow.
▪ How to use looping?
▪ Key words for Looping

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 24


What is looping in C?

Section of code in a program


which is executed repeatedly,
until a specific condition is satisfied

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 25


Syntax

The for loop


The while loop
The do….while loop

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 26


Syntax: The for loop

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 27


Syntax: The while loop

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 28


Syntax: The do….while loop

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 29


Enter and exit, break looping follow.

Enter and exit, break looping follow ?

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 30


How to use looping?

- Know number of loop.


- Unknow number of loop.

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 31


Key words for Looping

- Goto
- Continue
- Exit()
- Break()
- Return

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 32


Key words for Looping: Goto

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 33


Key words for Looping: Continue

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 34


Key words for Looping: Exit()

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 35


Key words for Looping: Break()

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 36


Key words for Looping: Return

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 37


Looping In C. Summary

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 38


Lesson Summary

▪ Array in C
▪ Decision in C
▪ Looping In C

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 39


Thank you

3/5/2024 09e-BM/DT/FSOFT - ©FPT SOFTWARE – Fresher Academy - Internal Use 40

You might also like