SlideShare a Scribd company logo
LOGO

Higher Technological Institute
10th of Ramadan City
6th of October Branch
Electrical and Computer Engineering Department

Lecture Notes in

Prepaid By: Eng. Ibrahim Elewah
Main Reference
HTI Student Book and “C For Dummies”

by Dan Gookin 2nd Edition

1
Course Contents
1

Introduction

2

Program Development

3

The Essential of C Programs

4

Manipulating Data with Operators

5

Reading from and Writing to Standard I/O

6

Decision

7

Iteration

8

Arrays

9

C Functions
C Programming

2

Higher Technological Institute
Course Contents
3

The Essential of C Programs

 Constants and variables
 Expressions

 Arithmetic operators
 Statements

 Statement blocks
 Data Types and Names in C
 Naming a Variable
C Programming

3

Higher Technological Institute
Expressions
o An expression is a combination of constants,
variables, and operators that are used to
denote computations

𝑨= 𝟐∗ 𝑨 − 𝟏
1. Taking the value contained in the drawer
(variable) A
2. Multiply this value by 2
3. Subtract 1 from result obtained from 2
4. The value contained in drawer A is omitted, then
putting the result obtained from 3 into drawer A.
C Programming

4

Higher Technological Institute
Arithmetic Operations
Addition

Subtraction

Multiplication

Division

Reminder

The Reminder operator % is used to obtain
the reminder of the first operand divided by
the second operand
C Programming

5

Higher Technological Institute
Arithmetic Operations
Addition

Subtraction

Multiplication

Division

Reminder

Example
𝟔% 𝟒= 𝟐
C Programming

𝟏𝟎𝟎𝟏%𝟐 = 𝟏
6

𝟒𝟖%𝟓 =
Higher Technological Institute
Arithmetic Operations
Addition

Subtraction

Multiplication

Division

Reminder

Example
𝟔% 𝟒= 𝟐
C Programming

𝟏𝟎𝟎𝟏%𝟐 = 𝟏
7

𝟒𝟖%𝟓 = 𝟑
Higher Technological Institute
Constants and Variables
o As its name implies, a constant is a value that never
changes.
o A variable, on the other hand, can be used to present
different values.
o For instance, consider the following:

𝒊 = 𝟏 ;
o Where the symbol i is a constant because it always has
the same value (1) and the symbol i is assigned the
constant 1.
o In other words, i contains the value of 1 after the
statement is executed.
C Programming

8

Higher Technological Institute
Data Types and Names
o The C language reserves some keywords
words that have special meanings to the
language.
o Those reserved words should not be used
as variables, constants, or function names
in your program.
o All C keywords must be written in
lowercase letters, for instance INT will not
be treated as a keyword, it must be written
as int.
C Programming

9

Higher Technological Institute
The computer list of C keywords
auto
const
double
float
int
short
struct
unsigned
C Programming

break
continue
else
for
long
signed
switch
void

case
default
enum
goto
register
sizeof
typedef
volatile
10

char
do
extern
if
return
static
union
while
Higher Technological Institute
Naming a Variable
Valid Variable Name Can Use
o Characters A through Z and a through z
o Digit characters 0 through 9, which can be
used in any position except the first of a
variable name.
o The underscore character _

Examples
stop_sign
C Programming

loop3
11

and_pause
Higher Technological Institute
Naming a Variable
Invalid Variable Name Can NOT be Used
o
o
o
o

A variable name can’t contain any C arithmetic signs.
A variable name can’t contain any dots.
A variable name can’t contain any apostrophes.
A variable name can’t contain any other special
symbols such as *, @, #, and so on.

Examples
4flags
return
C Programming

sum-result
what_size?
12

method*4
ahmed.ali
Higher Technological Institute
Data Types

C Data Type
char

int

float

double

a, B, $, #

5, 17, 128

2.5 , 0.3

23433.3455

C Programming

13

Higher Technological Institute
Declaration Statement

Type

Name Value

char
int
float
double

c1
N1
F1
d1

char c1

= ‘&’ ;

int

‘&’
100
32/10
5e3

= 100 ;

n1

C Programming

14

Higher Technological Institute
Declaration Statement

Type
char
int
float
double

Name Value
‘&’
100
32/10
5e3

c1
N1
F1
d1

char c1

;

c1

= ‘&’ ;

int

;

n1

= 100 ;

n1

C Programming

15

Higher Technological Institute
Declaration Statement

Type

Name Value

char
int
float
double

float

c1
n1
f1
d1

‘&’
100
32/10
5e3

f1= 32/100 ;

double
C Programming

d1=5e3 ;
16

Higher Technological Institute
Declaration Statement

Type

Name Value

char
int
float
double

‘&’
100
32/10
5e3

c1
n1
f1
d1

float

f1

;

f1

=

32/100 ;

double

d1 ;

d1

=

5e3

C Programming

17

;

Higher Technological Institute
Some special characters in C

b

Backspace

f

Form feed

n

New line

r

Return

t

Tab

C Programming

Moves the cursor to the left
one character
Goes to the top of a new
page
Carriage return and line
feeds
Returns to the beginning of
the current line
Advances to the next tab
stop
18

Higher Technological Institute
Examples
/* Example1 : Printing out characters */
# include <stdio.h>
/* the header file for the printf () function */
main ( )
{
/* the main function body till line 13 */
char c1;
/* declaration of the character variable c1 */
char c2;
/* declaration of the character variable c2 */
c1 = ‘A’; /* assigning c1 with the character constant A */
c2 = ‘a’; /* assigning c2 with the character constant a */
return 0;
}

C Programming

19

Higher Technological Institute
Examples
/* Example1 : Printing out characters */
# include <stdio.h>
/* the header file for the printf () function */
main ( )
{
/* the main function body till line 13 */
char c1;
/* declaration of the character variable c1 */
char c2;
/* declaration of the character variable c2 */
c1 = ‘A’;
/* assigning c1 with the character constant A */
c2 = ‘a’;
/* assigning c2 with the character constant a */
printf ( “ The character c1 is : %c n ”, c1);
printf ( “ The character c1 is : %c ” , c1);
printf ( “ while the character c2 is : %c n”, c2);
return 0;
}
C Programming

20

Higher Technological Institute
Examples
/* Example1 : Printing out characters */
# include <stdio.h>
/* the header file for the printf () function */
main ( )
{
/* the main function body till line 13 */
char c1;
/* declaration of the character variable c1 */
printf ( “ The character c1 is : variablen */”, c1);
%c c2
char c2;
/* declaration of the character
c1 = ‘A’;
/* assigning c1 with the character constant A */
c2 = ‘a’;
/* assigning c2 with the character constant a */
printf ( “ The character c1 is : %c n ”, c1);
printf ( “ The character c1 is : %c ” , c1);
printf ( “ while the character c2 is : %c n”, c2);
return 0;
}
C Programming

21

Higher Technological Institute
Examples
/* Example1 : Printing out characters */
# include <stdio.h>
/* the header file for the printf () function */
main ( )
{
/* the main function body till line 13 */
char c1;
/* declaration of the character variable c1 */
printf ( “ The character c1 is : variablen */”, c1);
%c c2
char c2;
/* declaration of the character
c1 = ‘A’;
/* assigning c1 with the character constant A */
c2 = ‘a’;
/* assigning c2 with the character constant a */
printf ( “ The character c1 is : %c n ”, c1);
printf ( “ The character c1 is : %c ” , c1);
printf ( “ while the character c2 is : %c n”, c2);
return 0;
}
C Programming

22

Higher Technological Institute
Examples
/* Example1 : Printing out characters */
# include <stdio.h>
/* the header file for the printf () function */
main ( )
{
/* the main function body till line 13 */
char c1;
/* declaration of the character variable c1 */
printf ( “ The character c1 is : variablen */”, c1);
%c c2
char c2;
/* declaration of the character
c1 = ‘A’;
/* assigning c1 with the character constant A */
c2 = ‘a’;
/* assigning c2 with the character constant a */
printf ( “ The character c1 is : %c n ”, c1);
printf ( “ The character c1 is : %c ” , c1);
printf ( “ while the character c2 is : %c n”, c2);
return 0;
}
C Programming

23

Higher Technological Institute
Examples
/* Example1 : Printing out characters */
# include <stdio.h>
/* the header file for the printf () function */
main ( )
{
/* the main function body till line 13 */
char c1;
/* declaration of the character variable c1 */
printf ( “ The character c1 is : variablen */”, c1);
%c c2
char c2;
/* declaration of the character
c1 = ‘A’;
/* assigning c1 with the character constant A */
c2 = ‘a’;
/* assigning c2 with the character constant a */
printf ( “ The character c1 is : %c n ”, c1);
printf ( “ The character c1 is : %c ” , c1);
printf ( “ while the character c2 is : %c n”, c2);
return 0;
}

New Line

Specifier
for
Character Data Type

C Programming

24

Higher Technological Institute
Examples
/* Example1 : Printing out characters */
# include <stdio.h>
/* the header file for the printf () function */
main ( )
{
/* the main function body till line 13 */
char c1;
/* declaration of the character variable c1 */
char c2;
/* declaration of the character variable c2 */
c1 = ‘A’;
/* assigning c1 with the character constant A */
c2 = ‘a’;
/* assigning c2 with the character constant a */
printf ( “ The character c1 is : %c n ”, c1);
printf ( “ The character c1 is : %c ” , c1);
printf ( “ while the character c2 is : %c n”, c2);
return 0;
}
C Programming

25

Higher Technological Institute
You Have To Know about Data Types

Type

Name

Value

Specifier

char

c1

‘&’

%c

int

n1

100

%d

float

f1

32/10

%f

double

d1

5e3

%e,%E

C Programming

26

Higher Technological Institute
Examples
/* The arithmetic operations on integers */
# include<stdio.h>
/* the header file for the printf () function */
main ( )
{
/* the main function body till line 15 */
int m = 3;
int n=2;
printf ( "The summation of %d and %d is : %d.n", m, n, m+n);
printf ( "The difference between %d and %d is : %d.n", m, n, m-n);
printf ( "The multiplication of %d by %d is : %d.n", m, n, m*n);
printf ( "The division of %d by %d is : %d.n", m, n, m/n);
printf ( "The remainder of division of %d by %d is : %d.n", m, n, m%n);
return 0 ;
}

C Programming

27

Higher Technological Institute
Operators Precedence
Operator Sign
( )
/
*
+
-

C Programming

Name
Brackets
Division
Multiplication
Addition
Subtraction

28

Higher Technological Institute
Logic Operators

Operator Sign
||
&&
!=

C Programming

Name
OR
AND
NOT

29

Higher Technological Institute
Examples
/* Example3 : Integer vs. floating point divisions */
# include <stdio.h>
/* the header file for the printf ()
function */
main ( )
{
int n1,n2,n3;
float m1,m2,m3;
n1 = 32/10;
m1= 32/10;
n2 = 32.0/10;
m2= 32.0/10;
n3 = 32/10.0;
m3 = 32/10.0;
return 0;
}
C Programming

30

Higher Technological Institute
Examples
/* Example3 : Integer vs. floating point divisions */
# include <stdio.h>
/* the header file for the printf () function */
main ( )
{
int n1,n2,n3;
float m1,m2,m3;
n1 = 32/10;
m1= 32/10;
n2 = 32.0/10;
m2= 32.0/10;
n3 = 32/10.0;
m3 = 32/10.0;
printf ( “ The integer division of 32/10 is :
%d n”, n1);
printf ( “The floating point division of 32/10 is :
%f n”, m1);
printf ( “The integer division of 32.0/10 is :
%d n”, n2);
printf ( “The floating point division of 32.0/10 is :
%f n”, m2);
printf ( “The integer division of 32/10.0 is :
%d n”, n3);
printf ( “The floating point division of 32/10.0 is :
%f n”, m3);
return 0;
}
C Programming

31

Higher Technological Institute
Double Data Type
o Here are two examples:
[mantissa] e [exponent]
[mantissa] E [exponent]

Example
5000
-300
0.0025

5e3.
-3e2
2.5e-3.

Specifier %e or %E
With printf ( )
C Programming

32

Higher Technological Institute
Precedence Example
# include<stdio.h>
main ( )
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

33

Higher Technological Institute
Precedence Example
# include<stdio.h>
main ( )
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

34

Higher Technological Institute
Precedence Example
# include<stdio.h>
X(
B/C + A ;
main = ) E * D –
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

35

Higher Technological Institute
Precedence Example

X= E*D –

X= E*D –

C Programming

B/C

B/C

+ A ;

+ A ;

36

Higher Technological Institute
Precedence Example

X= E*D –

C Programming

B/C + A ;

37

Higher Technological Institute
Precedence Example

X= E*D –

B/C + A ;

A = 20
B=6
C=3
D = 10
E=2

C Programming

( )
*
/
+-

38

Higher Technological Institute
Precedence Example

X= E*D –
2 * 10 –
A = 20

B/C + A ;
6 / 3 + 20

B=6
C=3
D = 10
E=2

C Programming

39

( )
*
/
+-

Higher Technological Institute
Precedence Example

X= E*D –
2 * 10 –
A = 20
B=6
C=3
D = 10
E=2

C Programming

20

B/C + A ;
6 / 3 + 20

–

2

40

+ 20

( )
*
/
+-

Higher Technological Institute
Precedence Example

X= E*D –
2 * 10 –
A = 20
B=6
C=3
D = 10
E=2

C Programming

20

B/C + A ;
6 / 3 + 20

–

2
38

41

+ 20

( )
*
/
+-

Higher Technological Institute
Precedence Example
# include<stdio.h>
main ( )
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

42

Higher Technological Institute
Precedence Example
# include<stdio.h>
main ( )
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

43

Higher Technological Institute
Precedence Example
# include<stdio.h>
main = )( E * D ) – ( B / C ) + A ;
Y (
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

44

Higher Technological Institute
Precedence Example

Y=(E*D)–(B/C)+ A ;

.
.
.

C Programming

45

Higher Technological Institute
Precedence Example

Y=(E*D)–(B/C)+ A ;

.
.
.
38

C Programming

46

Higher Technological Institute
Precedence Example
# include<stdio.h>
main ( )
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

47

Higher Technological Institute
Precedence Example
# include<stdio.h>
Z( = A * ( D – B ) / ( C + E ) ;
main )
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

48

Higher Technological Institute
Precedence Example

Z= A*(D–B)/(C+ E);
A = 20
B=6
C=3
D = 10
E=2

C Programming

( )
*
/
+-

49

Higher Technological Institute
Precedence Example

Z= A*(D–B)/(C+ E);
A = 20
B=6
C=3
D = 10
E=2

C Programming

( )
*
/
+-

50

Higher Technological Institute
Precedence Example

Z= A*(D–B)/(C+ E);
A = 20
B=6
C=3
D = 10
E=2

C Programming

20 *

4

/

51

5

( )
*
/
+-

Higher Technological Institute
Precedence Example

Z= A*(D–B)/(C+ E);
A = 20
B=6
C=3
D = 10
E=2

C Programming

20 *

4

/

16

52

5

( )
*
/
+-

Higher Technological Institute
Precedence Example
# include<stdio.h>
main ( )
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

53

Higher Technological Institute
Precedence Example
# include<stdio.h>
main ( )
{
int A,B,C,D,E, X, Y, Z;
A = 20 ; B = 6 ;
C = 3 ; D = 10 ; E = 2 ;
X= E*D – B/C + A ;
Y=(E*D)–(B/C)+ A ;
Z= A*(D–B)/(C+ E);
printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z);
return 0 ;
}
C Programming

54

Higher Technological Institute
Home Work ..!!
Exercises 3 Page 44
C Programming

55

Higher Technological Institute
LOGO

Higher Technological Institute
10th of Ramadan City
6th of October Branch
Electrical and Computer Engineering Department

Eng. Ibrahim Elewah
Main Reference
HTI Student Book and “C For Dummies”

by Dan Gookin 2nd Edition

56
Ad

More Related Content

What's hot (20)

Loops in c
Loops in cLoops in c
Loops in c
baabtra.com - No. 1 supplier of quality freshers
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
St. Petersburg College
 
C programming for problem solving
C programming for problem solving  C programming for problem solving
C programming for problem solving
Anuradha Moti T
 
Programming in c
Programming in cProgramming in c
Programming in c
indra Kishor
 
Deep C
Deep CDeep C
Deep C
Olve Maudal
 
C functions
C functionsC functions
C functions
University of Potsdam
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
Vivek Singh Chandel
 
PPS UNIT 1- R18.docx
PPS UNIT 1- R18.docxPPS UNIT 1- R18.docx
PPS UNIT 1- R18.docx
Uzma1102
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Edureka!
 
Computer Organisation
Computer OrganisationComputer Organisation
Computer Organisation
LaxmiDevi38
 
digital computers
digital computersdigital computers
digital computers
HumaKhan156
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
primeteacher32
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
Prof. Dr. K. Adisesha
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
Programming Language Evolution
Programming Language EvolutionProgramming Language Evolution
Programming Language Evolution
Kushan Dananjaya
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
gourav kottawar
 
Global Trend CHAPTER ONE jjjiiiuyy I iuyy.pdf
Global Trend  CHAPTER ONE jjjiiiuyy I iuyy.pdfGlobal Trend  CHAPTER ONE jjjiiiuyy I iuyy.pdf
Global Trend CHAPTER ONE jjjiiiuyy I iuyy.pdf
seraphimkassa
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
Himanshu Kaushik
 
C programming for problem solving
C programming for problem solving  C programming for problem solving
C programming for problem solving
Anuradha Moti T
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
Neeru Mittal
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
Vivek Singh Chandel
 
PPS UNIT 1- R18.docx
PPS UNIT 1- R18.docxPPS UNIT 1- R18.docx
PPS UNIT 1- R18.docx
Uzma1102
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Edureka!
 
Computer Organisation
Computer OrganisationComputer Organisation
Computer Organisation
LaxmiDevi38
 
digital computers
digital computersdigital computers
digital computers
HumaKhan156
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
Programming Language Evolution
Programming Language EvolutionProgramming Language Evolution
Programming Language Evolution
Kushan Dananjaya
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
gourav kottawar
 
Global Trend CHAPTER ONE jjjiiiuyy I iuyy.pdf
Global Trend  CHAPTER ONE jjjiiiuyy I iuyy.pdfGlobal Trend  CHAPTER ONE jjjiiiuyy I iuyy.pdf
Global Trend CHAPTER ONE jjjiiiuyy I iuyy.pdf
seraphimkassa
 

Viewers also liked (8)

Chapter 3
Chapter 3Chapter 3
Chapter 3
Nadine Guevarra
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
Ngeam Soly
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
Macky Gepana
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chapters
Ibrahim Elewah
 
Chapter iii
Chapter iiiChapter iii
Chapter iii
Carie Justine Estrellado
 
Data gathering
Data gatheringData gathering
Data gathering
Chie Pegollo
 
Writing chapter 3
Writing chapter 3Writing chapter 3
Writing chapter 3
Centro Escolar University
 
Ad

Similar to Computer programming chapter ( 3 ) (20)

c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
RohitRaj744272
 
The Basics of C - Math Functions and characters
The Basics of C - Math Functions and charactersThe Basics of C - Math Functions and characters
The Basics of C - Math Functions and characters
uapinturzhan
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
Programming in C.pptx
Programming in C.pptxProgramming in C.pptx
Programming in C.pptx
TeresitaDapulase
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
atulchaudhary821
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
Anil Bishnoi
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Leandro Schenone
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184
Sumit Saini
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
Minh Thắng Trần
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
indrasir
 
C programming
C programmingC programming
C programming
saniabhalla
 
Unit4
Unit4Unit4
Unit4
MOHAMAD NOH AHMAD
 
C Programming
C ProgrammingC Programming
C Programming
Adil Jafri
 
C Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptxC Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptx
kumaranand07297
 
Cnotes
CnotesCnotes
Cnotes
Muthuganesh S
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
RohitRaj744272
 
The Basics of C - Math Functions and characters
The Basics of C - Math Functions and charactersThe Basics of C - Math Functions and characters
The Basics of C - Math Functions and characters
uapinturzhan
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt(Lect. 2 & 3) Introduction to C.ppt
(Lect. 2 & 3) Introduction to C.ppt
atulchaudhary821
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
Anil Bishnoi
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184
Sumit Saini
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
indrasir
 
C Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptxC Language ppt create by Anand & Sager.pptx
C Language ppt create by Anand & Sager.pptx
kumaranand07297
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
Ad

Recently uploaded (20)

ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Change Sequence Number in Odoo 18 Sale Order
How to Change Sequence Number in Odoo 18 Sale OrderHow to Change Sequence Number in Odoo 18 Sale Order
How to Change Sequence Number in Odoo 18 Sale Order
Celine George
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdfIPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
Quiz Club of PSG College of Arts & Science
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdfAntepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Dr H.K. Cheema
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
ITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQ
SONU HEETSON
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-17-2025 .pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-17-2025  .pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-17-2025  .pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-17-2025 .pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic SuccessAerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
online college homework help
 
Conditions for Boltzmann Law – Biophysics Lecture Slide
Conditions for Boltzmann Law – Biophysics Lecture SlideConditions for Boltzmann Law – Biophysics Lecture Slide
Conditions for Boltzmann Law – Biophysics Lecture Slide
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Change Sequence Number in Odoo 18 Sale Order
How to Change Sequence Number in Odoo 18 Sale OrderHow to Change Sequence Number in Odoo 18 Sale Order
How to Change Sequence Number in Odoo 18 Sale Order
Celine George
 
How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18How to Use Upgrade Code Command in Odoo 18
How to Use Upgrade Code Command in Odoo 18
Celine George
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdfAntepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Dr H.K. Cheema
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
ITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQITI COPA Question Paper PDF 2017 Theory MCQ
ITI COPA Question Paper PDF 2017 Theory MCQ
SONU HEETSON
 
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptxUnit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Unit 5 ACUTE, SUBACUTE,CHRONIC TOXICITY.pptx
Mayuri Chavan
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docxPeer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
Peer Assessment_ Unit 2 Skills Development for Live Performance - for Libby.docx
19lburrell
 
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic SuccessAerospace Engineering Homework Help Guide – Expert Support for Academic Success
Aerospace Engineering Homework Help Guide – Expert Support for Academic Success
online college homework help
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 

Computer programming chapter ( 3 )

  • 1. LOGO Higher Technological Institute 10th of Ramadan City 6th of October Branch Electrical and Computer Engineering Department Lecture Notes in Prepaid By: Eng. Ibrahim Elewah Main Reference HTI Student Book and “C For Dummies” by Dan Gookin 2nd Edition 1
  • 2. Course Contents 1 Introduction 2 Program Development 3 The Essential of C Programs 4 Manipulating Data with Operators 5 Reading from and Writing to Standard I/O 6 Decision 7 Iteration 8 Arrays 9 C Functions C Programming 2 Higher Technological Institute
  • 3. Course Contents 3 The Essential of C Programs  Constants and variables  Expressions  Arithmetic operators  Statements  Statement blocks  Data Types and Names in C  Naming a Variable C Programming 3 Higher Technological Institute
  • 4. Expressions o An expression is a combination of constants, variables, and operators that are used to denote computations 𝑨= 𝟐∗ 𝑨 − 𝟏 1. Taking the value contained in the drawer (variable) A 2. Multiply this value by 2 3. Subtract 1 from result obtained from 2 4. The value contained in drawer A is omitted, then putting the result obtained from 3 into drawer A. C Programming 4 Higher Technological Institute
  • 5. Arithmetic Operations Addition Subtraction Multiplication Division Reminder The Reminder operator % is used to obtain the reminder of the first operand divided by the second operand C Programming 5 Higher Technological Institute
  • 6. Arithmetic Operations Addition Subtraction Multiplication Division Reminder Example 𝟔% 𝟒= 𝟐 C Programming 𝟏𝟎𝟎𝟏%𝟐 = 𝟏 6 𝟒𝟖%𝟓 = Higher Technological Institute
  • 7. Arithmetic Operations Addition Subtraction Multiplication Division Reminder Example 𝟔% 𝟒= 𝟐 C Programming 𝟏𝟎𝟎𝟏%𝟐 = 𝟏 7 𝟒𝟖%𝟓 = 𝟑 Higher Technological Institute
  • 8. Constants and Variables o As its name implies, a constant is a value that never changes. o A variable, on the other hand, can be used to present different values. o For instance, consider the following: 𝒊 = 𝟏 ; o Where the symbol i is a constant because it always has the same value (1) and the symbol i is assigned the constant 1. o In other words, i contains the value of 1 after the statement is executed. C Programming 8 Higher Technological Institute
  • 9. Data Types and Names o The C language reserves some keywords words that have special meanings to the language. o Those reserved words should not be used as variables, constants, or function names in your program. o All C keywords must be written in lowercase letters, for instance INT will not be treated as a keyword, it must be written as int. C Programming 9 Higher Technological Institute
  • 10. The computer list of C keywords auto const double float int short struct unsigned C Programming break continue else for long signed switch void case default enum goto register sizeof typedef volatile 10 char do extern if return static union while Higher Technological Institute
  • 11. Naming a Variable Valid Variable Name Can Use o Characters A through Z and a through z o Digit characters 0 through 9, which can be used in any position except the first of a variable name. o The underscore character _ Examples stop_sign C Programming loop3 11 and_pause Higher Technological Institute
  • 12. Naming a Variable Invalid Variable Name Can NOT be Used o o o o A variable name can’t contain any C arithmetic signs. A variable name can’t contain any dots. A variable name can’t contain any apostrophes. A variable name can’t contain any other special symbols such as *, @, #, and so on. Examples 4flags return C Programming sum-result what_size? 12 method*4 ahmed.ali Higher Technological Institute
  • 13. Data Types C Data Type char int float double a, B, $, # 5, 17, 128 2.5 , 0.3 23433.3455 C Programming 13 Higher Technological Institute
  • 14. Declaration Statement Type Name Value char int float double c1 N1 F1 d1 char c1 = ‘&’ ; int ‘&’ 100 32/10 5e3 = 100 ; n1 C Programming 14 Higher Technological Institute
  • 15. Declaration Statement Type char int float double Name Value ‘&’ 100 32/10 5e3 c1 N1 F1 d1 char c1 ; c1 = ‘&’ ; int ; n1 = 100 ; n1 C Programming 15 Higher Technological Institute
  • 16. Declaration Statement Type Name Value char int float double float c1 n1 f1 d1 ‘&’ 100 32/10 5e3 f1= 32/100 ; double C Programming d1=5e3 ; 16 Higher Technological Institute
  • 18. Some special characters in C b Backspace f Form feed n New line r Return t Tab C Programming Moves the cursor to the left one character Goes to the top of a new page Carriage return and line feeds Returns to the beginning of the current line Advances to the next tab stop 18 Higher Technological Institute
  • 19. Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ return 0; } C Programming 19 Higher Technological Institute
  • 20. Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 20 Higher Technological Institute
  • 21. Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 21 Higher Technological Institute
  • 22. Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 22 Higher Technological Institute
  • 23. Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 23 Higher Technological Institute
  • 24. Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ printf ( “ The character c1 is : variablen */”, c1); %c c2 char c2; /* declaration of the character c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } New Line Specifier for Character Data Type C Programming 24 Higher Technological Institute
  • 25. Examples /* Example1 : Printing out characters */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 13 */ char c1; /* declaration of the character variable c1 */ char c2; /* declaration of the character variable c2 */ c1 = ‘A’; /* assigning c1 with the character constant A */ c2 = ‘a’; /* assigning c2 with the character constant a */ printf ( “ The character c1 is : %c n ”, c1); printf ( “ The character c1 is : %c ” , c1); printf ( “ while the character c2 is : %c n”, c2); return 0; } C Programming 25 Higher Technological Institute
  • 26. You Have To Know about Data Types Type Name Value Specifier char c1 ‘&’ %c int n1 100 %d float f1 32/10 %f double d1 5e3 %e,%E C Programming 26 Higher Technological Institute
  • 27. Examples /* The arithmetic operations on integers */ # include<stdio.h> /* the header file for the printf () function */ main ( ) { /* the main function body till line 15 */ int m = 3; int n=2; printf ( "The summation of %d and %d is : %d.n", m, n, m+n); printf ( "The difference between %d and %d is : %d.n", m, n, m-n); printf ( "The multiplication of %d by %d is : %d.n", m, n, m*n); printf ( "The division of %d by %d is : %d.n", m, n, m/n); printf ( "The remainder of division of %d by %d is : %d.n", m, n, m%n); return 0 ; } C Programming 27 Higher Technological Institute
  • 28. Operators Precedence Operator Sign ( ) / * + - C Programming Name Brackets Division Multiplication Addition Subtraction 28 Higher Technological Institute
  • 29. Logic Operators Operator Sign || && != C Programming Name OR AND NOT 29 Higher Technological Institute
  • 30. Examples /* Example3 : Integer vs. floating point divisions */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { int n1,n2,n3; float m1,m2,m3; n1 = 32/10; m1= 32/10; n2 = 32.0/10; m2= 32.0/10; n3 = 32/10.0; m3 = 32/10.0; return 0; } C Programming 30 Higher Technological Institute
  • 31. Examples /* Example3 : Integer vs. floating point divisions */ # include <stdio.h> /* the header file for the printf () function */ main ( ) { int n1,n2,n3; float m1,m2,m3; n1 = 32/10; m1= 32/10; n2 = 32.0/10; m2= 32.0/10; n3 = 32/10.0; m3 = 32/10.0; printf ( “ The integer division of 32/10 is : %d n”, n1); printf ( “The floating point division of 32/10 is : %f n”, m1); printf ( “The integer division of 32.0/10 is : %d n”, n2); printf ( “The floating point division of 32.0/10 is : %f n”, m2); printf ( “The integer division of 32/10.0 is : %d n”, n3); printf ( “The floating point division of 32/10.0 is : %f n”, m3); return 0; } C Programming 31 Higher Technological Institute
  • 32. Double Data Type o Here are two examples: [mantissa] e [exponent] [mantissa] E [exponent] Example 5000 -300 0.0025 5e3. -3e2 2.5e-3. Specifier %e or %E With printf ( ) C Programming 32 Higher Technological Institute
  • 33. Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 33 Higher Technological Institute
  • 34. Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 34 Higher Technological Institute
  • 35. Precedence Example # include<stdio.h> X( B/C + A ; main = ) E * D – { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 35 Higher Technological Institute
  • 36. Precedence Example X= E*D – X= E*D – C Programming B/C B/C + A ; + A ; 36 Higher Technological Institute
  • 37. Precedence Example X= E*D – C Programming B/C + A ; 37 Higher Technological Institute
  • 38. Precedence Example X= E*D – B/C + A ; A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 38 Higher Technological Institute
  • 39. Precedence Example X= E*D – 2 * 10 – A = 20 B/C + A ; 6 / 3 + 20 B=6 C=3 D = 10 E=2 C Programming 39 ( ) * / +- Higher Technological Institute
  • 40. Precedence Example X= E*D – 2 * 10 – A = 20 B=6 C=3 D = 10 E=2 C Programming 20 B/C + A ; 6 / 3 + 20 – 2 40 + 20 ( ) * / +- Higher Technological Institute
  • 41. Precedence Example X= E*D – 2 * 10 – A = 20 B=6 C=3 D = 10 E=2 C Programming 20 B/C + A ; 6 / 3 + 20 – 2 38 41 + 20 ( ) * / +- Higher Technological Institute
  • 42. Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 42 Higher Technological Institute
  • 43. Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 43 Higher Technological Institute
  • 44. Precedence Example # include<stdio.h> main = )( E * D ) – ( B / C ) + A ; Y ( { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 44 Higher Technological Institute
  • 45. Precedence Example Y=(E*D)–(B/C)+ A ; . . . C Programming 45 Higher Technological Institute
  • 46. Precedence Example Y=(E*D)–(B/C)+ A ; . . . 38 C Programming 46 Higher Technological Institute
  • 47. Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 47 Higher Technological Institute
  • 48. Precedence Example # include<stdio.h> Z( = A * ( D – B ) / ( C + E ) ; main ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 48 Higher Technological Institute
  • 49. Precedence Example Z= A*(D–B)/(C+ E); A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 49 Higher Technological Institute
  • 50. Precedence Example Z= A*(D–B)/(C+ E); A = 20 B=6 C=3 D = 10 E=2 C Programming ( ) * / +- 50 Higher Technological Institute
  • 51. Precedence Example Z= A*(D–B)/(C+ E); A = 20 B=6 C=3 D = 10 E=2 C Programming 20 * 4 / 51 5 ( ) * / +- Higher Technological Institute
  • 52. Precedence Example Z= A*(D–B)/(C+ E); A = 20 B=6 C=3 D = 10 E=2 C Programming 20 * 4 / 16 52 5 ( ) * / +- Higher Technological Institute
  • 53. Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 53 Higher Technological Institute
  • 54. Precedence Example # include<stdio.h> main ( ) { int A,B,C,D,E, X, Y, Z; A = 20 ; B = 6 ; C = 3 ; D = 10 ; E = 2 ; X= E*D – B/C + A ; Y=(E*D)–(B/C)+ A ; Z= A*(D–B)/(C+ E); printf ( “ X= %d n Y= %d n Z=%d n”, X,Y,Z); return 0 ; } C Programming 54 Higher Technological Institute
  • 55. Home Work ..!! Exercises 3 Page 44 C Programming 55 Higher Technological Institute
  • 56. LOGO Higher Technological Institute 10th of Ramadan City 6th of October Branch Electrical and Computer Engineering Department Eng. Ibrahim Elewah Main Reference HTI Student Book and “C For Dummies” by Dan Gookin 2nd Edition 56
  翻译: