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

More Related Content

What's hot

introduction to c language
 introduction to c language introduction to c language
introduction to c language
Rai University
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
Mohammed Saleh
 
C basics
C   basicsC   basics
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Batra Centre
 
C language
C languageC language
C language
marar hina
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
AashutoshChhedavi
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
JEENA SARA VIJU
 
Abc c program
Abc c programAbc c program
Abc c program
Dayakar Siddula
 
Introduction to programming with c,
Introduction to programming with c,Introduction to programming with c,
Introduction to programming with c,
Hossain Md Shakhawat
 
Turbo C
Turbo CTurbo C
Turbo C
nat236
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
Hemantha Kulathilake
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Rokonuzzaman Rony
 
Programming in c notes
Programming in c notesProgramming in c notes
Programming in c notes
Sudharasanam Babu
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)
Shujaat Abbas
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Akshay Ithape
 

What's hot (20)

introduction to c language
 introduction to c language introduction to c language
introduction to c language
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
C basics
C   basicsC   basics
C basics
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 
C language
C languageC language
C language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Abc c program
Abc c programAbc c program
Abc c program
 
Introduction to programming with c,
Introduction to programming with c,Introduction to programming with c,
Introduction to programming with c,
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
Turbo C
Turbo CTurbo C
Turbo C
 
Book ppt
Book pptBook ppt
Book ppt
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Programming in c notes
Programming in c notesProgramming in c notes
Programming in c notes
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 

Viewers also liked

Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
Ngeam Soly
 

Viewers also liked (7)

Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter3: fundamental programming
Chapter3: fundamental programmingChapter3: fundamental programming
Chapter3: fundamental programming
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Chapter iii
Chapter iiiChapter iii
Chapter iii
 
Bullying research in filipino
Bullying research in filipinoBullying research in filipino
Bullying research in filipino
 
Data gathering
Data gatheringData gathering
Data gathering
 
Writing chapter 3
Writing chapter 3Writing chapter 3
Writing chapter 3
 

Similar to Computer programming chapter ( 3 )

c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
RohitRaj744272
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
JAYA
 
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 01Dushmanta 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
88 c-programs88 c-programs
88 c-programs
Minh Thắng Trần
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184
Sumit Saini
 
Cnotes
CnotesCnotes
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
G. H. Raisoni Academy of Engineering & Technology, Nagpur
 
Error correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-cError correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-c
Md Nazmul Hossain Mir
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
Mohamed Fawzy
 
C prog ppt
C prog pptC prog ppt
C prog ppt
xinoe
 

Similar to Computer programming chapter ( 3 ) (20)

c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
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
 
Programming in C.pptx
Programming in C.pptxProgramming in C.pptx
Programming in C.pptx
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Chapter3
Chapter3Chapter3
Chapter3
 
(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
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
88 c programs 15184
88 c programs 1518488 c programs 15184
88 c programs 15184
 
C programming
C programmingC programming
C programming
 
C Programming
C ProgrammingC Programming
C Programming
 
Cnotes
CnotesCnotes
Cnotes
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
Error correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-cError correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-c
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 

Recently uploaded

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 

Recently uploaded (20)

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 

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