Professional Documents
Culture Documents
ICP Textbook PDF
ICP Textbook PDF
Computer Programming
(DCE2364)
Outcome 1
Outcome 1
Computer Systems,
Computer Systems,
Content
Content
1-1
1-1
1-3
1-3
Operating System
1-7
Operating System
1-7
Computer Hardware
1-11
Computer Hardware
1-11
Outcome 2
Outcome 2
History of Compiler,
History of Compiler,
Content
Content
2-1
2-1
2-2
2-2
2-4
2-4
2-8
2-8
Outcome 3
Outcome 3
Content
Content
3-1
3-1
Development of Algorithms
3-2
Development of Algorithms
3-2
Pseudocode
3-5
Pseudocode
3-5
Flow Charting
3-17
Flow Charting
3-17
Summary
3-24
Summary
3-24
Outcome 4
Outcome 4
Content
Content
4-1
4-1
Programming Concepts
4-2
Programming Concepts
4-2
4-8
4-8
Statements
4-14
Statements
4-14
4-15
4-15
4-17
4-17
Operators
4-23
Operators
4-23
Summary
4-27
Summary
4-27
Outcome 5
Outcome 5
Content
Content
5-1
5-1
Outcome 6
Outcome 6
Content
Content
6-1
6-1
6-2
6-2
Summary
6-14
Summary
6-14
Outcome 7
Outcome 7
Content
Content
7-1
7-1
Definition
7-2
Definition
7-2
1-Dimensional Array
7-3
1-Dimensional Array
7-3
2-Dimensional Array
7-7
2-Dimensional Array
7-7
Examples
7-12
Examples
7-12
Pointers
7-14
Pointers
7-14
Character Strings
7-19
Character Strings
7-19
Summary
7-23
Summary
7-23
Outcome 8
Outcome 8
Content
Content
8-1
8-1
Introduction to Structure
8-2
Introduction to Structure
8-2
Function
8-9
Function
8-9
Summary
8-17
Summary
8-17
Appendix
Content
Appendix
Content
Appendix Outcome 4
Appendix Outcome 4
Appendix Outcome 5
14
Appendix Outcome 5
14
Appendix Outcome 6
22
Appendix Outcome 6
22
Appendix Outcome 7
35
Appendix Outcome 7
35
Appendix Outcome 8
67
Appendix Outcome 8
67
Outcome 1
Outcome 1
Computer Systems,
Computer Systems,
Programming
Programming
Chapter
Chapter
Objectives
What computer is
Objectives
What computer is
Types of computers
Types of computers
o General-purpose computers
o General-purpose computers
o Microcomputers
o Microcomputers
supercomputers
Computing modes
supercomputers
Computing modes
o Standalone computing
o Standalone computing
develop the ability to solve problems, and its very likely that
develop the ability to solve problems, and its very likely that
tools:
tools:
techniques
3. A programming language
techniques
3. A programming language
What is a
What is a
computer?
computer?
Special-Purpose
Special-Purpose
Computers
Computers
General-purpose
General-purpose
computers
computers
and store data, can process data and can produce data.
and store data, can process data and can produce data.
Microcomputers
follows:
follows:
Microcomputers
Microcomputers
o Laptop computers
o Laptop computers
o Desktop computers
o Desktop computers
o Workstation
o Workstation
Minicomputers
Minicomputers
Mainframe Computers
Mainframe Computers
Supercomputers
Supercomputers
Microcomputers
computers.
computers.
and
Supercomputers
Computing modes
Minicomputers,
Mainframes
data
Supercomputers
and
operate
at
significantly
faster
speeds.
and
operate
at
significantly
faster
speeds.
mainframes.
mainframes.
Mainframes
computers
are
large-scale
Mainframes
computers
are
large-scale
on.
on.
Computing modes
1.
Standalone computing
1.
Standalone computing
2.
2.
3.
Distributed computing
3.
Distributed computing
4.
Client/server computing
4.
Client/server computing
Standalone
Standalone
Computing
Computing
Multiprogramming
Multiprogramming
Distributed
Distributed
Computing
Computing
Client/Server
Client/Server
Computing
Computing
clients, can make use of these programs and data. This type of
clients, can make use of these programs and data. This type of
Operating System
Operating System
The Operating
The Operating
System
System
NOS
resources to users.
resources to users.
MS-DOS
MS-DOS
Windows 95/98/2000/ME
Windows 95/98/2000/ME
Windows NT
Windows NT
Unix
Unix
Linux
Linux
NOS
Operating System
Operating System
Sharing (ICS).
Sharing (ICS).
smoothly.
smoothly.
Peer-to-Peer
Peer-to-Peer
Client/Server
Client/Server
Operating System
Peer to Peer
Client Server
Operating System
Peer to Peer
they all have the same abilities to use the resources available
they all have the same abilities to use the resources available
Client Server
file servers. The file servers become the heart of the system,
file servers. The file servers become the heart of the system,
Operating System
Operating System
Examples of
Examples of
network operating
network operating
systems
o Microsoft Windows 95 / 98
systems
o Microsoft Windows 95 / 98
Computer Hardware
Computer Hardware
Components of
Components of
computer
components:
computer
components:
hardware
Main Memory
hardware
o Main memory
o Main memory
o Input devices
o Input devices
o Output devices
o Output devices
Main Memory
representations
representations
for
program
instructions,
numeric
or
for
program
instructions,
numeric
or
Computer Hardware
Computer Hardware
Central Processing
Central Processing
Unit
Unit
Input Devices
data from the main memory and executes the instruction using
data from the main memory and executes the instruction using
computer components.
computer components.
operation.
operation.
Input Devices
solving.
solving.
Computer Hardware
Output Devices
Computer Hardware
Output Devices
Secondary
Secondary
Memory Devices
Memory Devices
expensive.
expensive.
Outcome 2
Outcome 2
History Of Compiler,
History Of Compiler,
Introduction
translator
translator
and
4GL.
The
history
and
evolution
of
and
4GL.
The
history
and
evolution
evolution
3. Understand
evolution
the
basic
terminology
used
programming
. 4. Understand the Operation System & Multi-tasking
in
3. Understand
the
basic
terminology
used
programming
. 4. Understand the Operation System & Multi-tasking
in
of
A compiler translates the code into machine code (1s and 0s),
A compiler translates the code into machine code (1s and 0s),
.COM or .EXE.
.COM or .EXE.
executed by an interpreter.
executed by an interpreter.
4GLs
being run.
being run.
necessary.
necessary.
4GLs
Computer
Computer
Program and
Program and
Programming
Programming
Language
Language
software.
software.
1. Machine Language
1. Machine Language
2. Assembly Language
2. Assembly Language
etc.
4. Functional,
etc.
Object
Oriented
and
Declarative
4. Functional,
Object
Oriented
and
Declarative
History of
1957 FORTRAN
History of
1957 FORTRAN
Programming
1958 ALGOL
Programming
1958 ALGOL
Language
1960 LISP
Language
1960 LISP
1960 COBOL
1960 COBOL
1962 APL
1962 APL
1962 SIMULA
1962 SIMULA
1964 BASIC
1964 BASIC
1964 PL/I
1964 PL/I
1966 ISWIM
1966 ISWIM
1970 Prolog
1970 Prolog
1972 C
1972 C
1975 Pascal
1975 Pascal
1975 Scheme
1975 Scheme
1977 OPS5
1977 OPS5
1978 CSP
1978 CSP
1978 FP
1978 FP
1980 dBASE II
1980 dBASE II
1983 Smalltalk-80
1983 Smalltalk-80
1983 Ada
1983 Ada
1983 Parlog
1983 Parlog
1984 Standard ML
1984 Standard ML
1986 C++
1986 C++
1986 CLP(R)
1986 CLP(R)
1986 Eiffel
1986 Eiffel
1988 CLOS
1988 CLOS
1988 Mathematica
1988 Mathematica
1988 Oberon
1988 Oberon
1990 Haskell
1990 Haskell
The Origins of C
The Origins of C
and C++:
and C++:
assembly language.
assembly language.
programmers.
programmers.
a way that they act just like the predefined types which are
a way that they act just like the predefined types which are
programming.
programming.
1. Source Code
1. Source Code
programming
programming
machine
machine
language,
the
language
that
the
computer
language,
the
language
that
the
computer
2. Program
2. Program
3. Instruction
3. Instruction
4. Variables
4. Variables
memory addresses.
memory addresses.
5. Computer Program
5. Computer Program
processor.
processor.
6. Programming language
6. Programming language
Basic, Pascal, C, C++, Java, Perl -- just like there are many
Basic, Pascal, C, C++, Java, Perl -- just like there are many
Outcome 3
Outcome 3
Programming Tools
Programming Tools
and Concepts
and Concepts
Introduction
2. Pseudocode
2. Pseudocode
3. Flow Chart
3. Flow Chart
3-1
Development of Algorithms
Algorithm
Development of Algorithms
Algorithm
executed.
executed.
3-2
Development of Algorithms
Development of Algorithms
unacceptable.
unacceptable.
computer.
computer.
There
are
techniques
developed
expressly
for
the
There
are
techniques
developed
expressly
for
the
Example of
Let's say that you have a friend arriving at the airport, and
Example of
Let's say that you have a friend arriving at the airport, and
Algorithm
your friend needs to get from the airport to your house. Here
Algorithm
your friend needs to get from the airport to your house. Here
are four different algorithms that you might give your friend
are four different algorithms that you might give your friend
2. Get in a taxi.
2. Get in a taxi.
3-3
Development of Algorithms
The rent-a-car algorithm:
Development of Algorithms
The rent-a-car algorithm:
2. Rent a car.
2. Rent a car.
3-4
Pseudocode
Introduction
Pseudocode
An outline of a program, written in a form that can easily be
Introduction
switch them
switch them
programming
programming
language
you
will
use
for
the
final
implementation.
language
you
will
use
for
the
final
implementation.
3-5
Pseudocode
Usage of
Pseudocode
Pseudocode
Usage of
Pseudocode
expansion purposes.
expansion purposes.
pseudocode must
pseudocode must
2. Be easy to learn
2. Be easy to learn
their complexity
their complexity
The Sequential
The Sequential
Control Structure
Control Structure
algorithm.
algorithm.
3-6
Pseudocode
Pseudocode
Begin
Begin
Read taxable income
Read filing status
Computer income tax
Print income tax
End
End
The Selection
The Selection
Control Structure
Control Structure
If condition
Then part
Else
Else part
End if
If condition
Then part
Else
Else part
End if
3-7
Pseudocode
Pseudocode
considered.
considered.
Example:
Example:
print tax
print tax
becomes:
becomes:
if condition
then part
end if
if condition
then part
end if
3-8
Pseudocode
Pseudocode
Here is an example:
Here is an example:
if status is equal to 1
print Single
end if
if status is equal to 1
print Single
end if
Nested Selection
Nested Selection
Structure
Structure
if status is equal to 1
print Single
else
if status is equal to 2
print Married filing jointly
else
if status is equal to 3
print Married filing separately
else
print Error in status code
end if
end if
end if
if status is equal to 1
print Single
else
if status is equal to 2
print Married filing jointly
else
if status is equal to 3
print Married filing separately
else
print Error in status code
end if
end if
end if
The Repetition
The Repetition
Control Structure
Control Structure
is satisfied.
is satisfied.
3-9
Pseudocode
Pseudocode
while condition
loop-body
end while
while condition
loop-body
end while
following pseudocode:
following pseudocode:
set CorrectStatusInput to n
set CorrectStatusInput to n
Pseudocode
Pseudocode
Conventions for
Conventions for
Pseudocode
Pseudocode
consists of the keywords if, else, while, begin, end, end_if and
consists of the keywords if, else, while, begin, end, end_if and
end_while.
end_while.
conventions.
conventions.
descriptions of operands.
descriptions of operands.
nonprogrammers to understand.
nonprogrammers to understand.
Pseudocode
Pseudocode
of an algorithm.
of an algorithm.
example:
example:
two roots and that they can be computed using the following
two roots and that they can be computed using the following
formulas:
formulas:
following:
following:
Pseudocode
Pseudocode
less than zero, we know that the roots are complex. In this
less than zero, we know that the roots are complex. In this
message on the screen that informs the user that the roots
message on the screen that informs the user that the roots
are complex.
are complex.
terminate.
terminate.
Analysis:
Analysis:
equation.
equation.
Pseudocode
Pseudocode
To:
To:
Pseudocode
And from:
Pseudocode
And from:
Solve the quadratic equation and print roots root1 and root2
To:
Solve the quadratic equation and print roots root1 and root2
To:
if a is equal to zero
if a is equal to zero
if a is equal to zero
if a is equal to zero
In this pseudocode,
In this pseudocode,
Pseudocode
Pseudocode
while loop.
while loop.
Set more to y
Set more to y
Your Task:
Your Task:
Flow Charting
Flow Chart
Flow Charting
A flowchart traces the flow of logic in a program and is very
Flow Chart
take.
take.
Flow Charting
Flow Charting
shown in the next table. The basic flowchart symbols are the
shown in the next table. The basic flowchart symbols are the
algorithm.
algorithm.
initializations.
initializations.
be read or written.
be read or written.
symbol.
symbol.
Flow Charting
Flow Charting
Flow Charting
Flow Charting
SEQUENTIAL STRUCTURE
Pseudocode
Statement 1
Statement2
..
Statement n
SEQUENTIAL STRUCTURE
Flowchart
Statement 1
Statement 2
...
Statement n
Pseudocode
Statement 1
Statement2
..
Statement n
SELECTION STRUCTURE
Pseudocode
Flowchart
false
if condition
then-part
end if
condi
tion
true
Flowchart
false
Else part
condi
tion
Statement 2
Flowchart
false
if condition
then-part
end if
then part
condi
tion
true
then part
SELECTION STRUCTURE
Pseudocode
true
...
SELECTION STRUCTURE
SELECTION STRUCTURE
if condition
then-part
else
else-part
end if
Statement 1
Pseudocode
then part
Pseudocode
Flowchart
if condition
then-part
else
else-part
end if
Flowchart
false
Else part
condi
tion
true
then part
Statement n
Flow Charting
Flow Charting
REPETITION STRUCTURE
Pseudocode
REPETITION STRUCTURE
Flowchart
While condition
Loop body
End_while
true
conditio
n
Pseudocode
Flowchart
While condition
Loop body
End_while
Loop body
true
conditio
n
false
Loop body
false
algorithm
algorithm
design
disadvantage
and
compared
representation,
to
it
pseudocoding.
has
For
certain
large
design
disadvantage
and
compared
representation,
to
it
pseudocoding.
has
For
certain
large
Flow Charting
Flow Charting
START
START
Prompt
user to
enter value
a,b and c
Prompt
user to
enter value
a,b and c
Read values
entered
Read values
entered
Print This
is not a
quadratic
equation
Yes
If a is equal to
zero
No
Computer the
roots of the
quadratic equation
Print This
is not a
quadratic
equation
Yes
If a is equal to
zero
Print the
final result
No
Computer the
roots of the
quadratic equation
Print the
final result
END
END
Flow Charting
Flow Charting
Tax Computation
Tax Computation
START
START
Set IncomeInput
to n
Set IncomeInput
to n
If IncomeInput equal
to n
true
Print enter
taxable income;
should be less
than 50000
If IncomeInput equal
to n
true
Read
income
false
Income
>=50000
Read
income
false
true
Income
>=50000
true
Set incomeinput to
y
false
END
Print enter
taxable income;
should be less
than 50000
Set incomeinput to
y
false
END
Summary
At a glance
Summary
At a glance
repetition structures.
repetition structures.
Outcome 4
Outcome 4
Output
Output
Chapter
Chapter
Objectives
Programming Concepts
Objectives
Programming Concepts
o Processor Directives
o Processor Directives
o Include Directive
o Include Directive
o Name Constant
o Name Constant
Statements
Statements
Operators
Operators
o Assignment operators
o Assignment operators
o Arithmetic operators
o Arithmetic operators
Programming Concepts
Programming Concepts
Definition of
Definition of
Programming
Programming
In summary,
In summary,
The Programming
Process
The Programming
Process
program.
program.
Programming Concepts
Programming Concepts
the desired
the desired
Program
Program
Development
Development
Cycle
Cycle
Programming Concepts
Programming Concepts
machine language.
are called object code, and the disk file containing them
are called object code, and the disk file containing them
compiler package.
compiler package.
compiler package.
compiler package.
Programming Concepts
Programming Concepts
A Brief History of
A Brief History of
C language
C language
Advantages of C
Readability
Advantages of C
Readability
Maintainability
Maintainability
library file.
library file.
Portability
Portability
Programming Concepts
Programming Concepts
peripherals easily.
peripherals easily.
Structure of C
Structure of C
1.
Program comments
1.
Program comments
2.
Preprocessor directives
2.
Preprocessor directives
3.
Type declarations
3.
Type declarations
4.
Named constant
4.
Named constant
5.
Statements
5.
Statements
6.
6.
7.
Function definitions
7.
Function definitions
8.
Function calls
8.
Function calls
Program
Program
Comments
Comments
// Preprocessor directives:
// Preprocessor directives:
program comments
program comments
and up-to-date.
and up-to-date.
after them.
after them.
Preprocessor
Preprocessor
Directives
Directives
1.
1.
2.
Conditional compilation
2.
Conditional compilation
3.
Macro substitution
3.
Macro substitution
its important.
its important.
of the header file stdio.h and the source program code and
of the header file stdio.h and the source program code and
printf()
printf()
scanf()
scanf()
sqrt()
sqrt()
exp()
exp()
where e is 2.718282
where e is 2.718282
abort()
rand()
0 to
abort()
exit()
void main()
Declarations
void main()
Declarations
double gross_income
double city_tax
double gross_income
double city_tax
1.
1.
2.
2.
3.
3.
those values.
those values.
1.
1.
2.
2.
1. int
1. int
follows:
follows:
signed int index = 41982;
2. char
2. char
3. float
3. float
CITY_TAX_RATE = 0.0185
CITY_TAX_RATE = 0.0185
Statements
Statements
A statement is a specification of an action to be taken by the
in the program.
in the program.
Compound
Compound
Statements
Statements
{
Statement;
Statement;
{
Statement;
Statement;
}
Statement;
Statement;
{
Statement;
Statement;
}
}
of braces, {}.
of braces, {}.
1. A type specifier
1. A type specifier
4. A compound statement
4. A compound statement
the program.
C/C++ 6.0
Main Menu
Windows
C/C++ 6.0
Main Menu
Windows
o File
o File
o Edit
o Edit
o Search
o Search
o Run
o Run
o Compile
o Compile
o Debug
o Debug
o Project
o Project
o Option
o Option
o Window
o Window
o Help
o Help
Message window
Message window
Source Code
Source Code
Editor
Editor
in this editor.
Message Window
in this editor.
Message Window
Variables
computer's memory.
Variable
Variable
Declarations
Declarations
character (_).
recommended.
recommended.
variables.
variables.
language.
language.
Example
Variable Name
Example
Legality
Variable Name
Legality
Percent
Legal
Percent
Legal
y2x5__fg7h
Legal
y2x5__fg7h
Legal
annual_profit
Legal
annual_profit
Legal
_1990_tax
_1990_tax
savings#account
savings#account
double
Illegal: Is a C keyword
double
Illegal: Is a C keyword
9winter
9winter
Numeric
Numeric
Variable Types
Variable Types
Fundamentals of
Fundamentals of
Input and
Input and
Output
scanf( )
Output
scanf( )
function.
function.
Conversion
Conversion
Specifier
Specifier
REMEMBER...
REMEMBER...
declaration.
declaration.
int num1;
int num1;
scanf command.
scanf command.
int num1;
int num1;
1. Literal text
1. Literal text
2. Escape sequence
2. Escape sequence
control.
3. Conversion specifier
Applied when the display involves the variables.
3. Conversion specifier
Applied when the display involves the variables.
REMEMBER ...
REMEMBER ...
variable declaration.
int num1=10;
int num1=10;
mismatch.
mismatch.
Operators
Operators
Operators are tokens that result in some kind of
elements in an expression.
elements in an expression.
2. Arithmetic operators
2. Arithmetic operators
3. Relational operators
3. Relational operators
4. Logical operators
4. Logical operators
Assignment
Assignment
operator
operator
variables.
variables.
Operators
Operators
Arithmetic
Arithmetic
Operators
Operators
arithmetic operators.
arithmetic operators.
one operand.
one operand.
Auto-increment, ++
Auto-increment, ++
Auto-decrement, - -
For example: - -x , x- -
Auto-decrement, - -
For example: - -x , x- -
two operands:
two operands:
Operators
Operators
Relational
Relational
Operators
Operators
C:
Logical Operators
C:
Logical Operators
Summary
Summary
This chapter at a
glance
This chapter at a
glance
name
name
Place
the
command
clrscr()
after
the
variable
Place
declaration.
the
command
clrscr()
after
the
variable
declaration.
Outcome 5
Outcome 5
Structures
Structures
Introduction
repetition statements.
repetition statements.
For statement
For statement
While statement
While statement
Do..while statement
Do..while statement
Purpose of
Purpose of
Looping
program,
Looping
program,
FOR Statement
which
involves
repeated
task.
Every
which
involves
repeated
task.
Every
FOR Statement
5-1
For example,
For example,
{
task 1;
task 1;
task 2;
task 2;
task 3;
task 3;
task 4;
task 4;
5-2
task 1;
task 1;
task 2;
task 2;
}
task 3;
task 3;
statement.
statement.
particular value.
particular value.
5-3
returns to step 2.
returns to step 2.
For example,
For example,
{
task 1;
task 1;
task 2;
task 2;
}
task 3;
task 3;
Nested FOR
Nested FOR
Statement
Statement
5-4
task 1;
task 1;
{
task 2;
task 3;
task 2;
FOR loop
within the
outer loop
task 3;
}
task 4;
FOR loop
within the
outer loop
task 4;
Statement...
Statement...
5-5
{
task 1;
task 1;
{
task 2;
task 2;
{
task 3;
task 3;
}
REMEMBER...
REMEMBER...
statement.
statement.
task 3;
task 3;
task 4;
task 4;
5-6
loop.
loop.
{
task 3;
task 3;
task 4;
task 4;
(like
(like
task 1;
task 1;
task 2;
task 2;
{
task 3;
task 3;
5-7
}.
}.
WHILE
WHILE
Statement
Statement
while (condition)
{
task 1;
task 2;
}
while (condition)
{
Condition is the
requirement / prerequisite to
execute the tasks within the
open braces and close
braces
task 1;
task 2;
}
Condition is the
requirement / prerequisite to
execute the tasks within the
open braces and close
braces
For example,
For example,
time = 2 am ;
while (time <=10 pm )
{
task 1;
task 2;
time = time + 2 hours;
}
time = 2 am ;
while (time <=10 pm )
{
task 1;
task 2;
time = time + 2 hours;
}
5-8
5-9
count1 = 1;
while (count1<=10)
{
task 1;
task 2;
++count1;
}
count1 = 1;
while (count1<=10)
{
task 1;
task 2;
++count1;
}
Difference
Difference
WHILE statement
WHILE statement
loop.
loop.
Nested While
Nested While
Statement
Statement
count1=1;
while (count1<=20)
{
task 1;
count2=1;
while (count2<=5)
{
task 2;
++count2;
}
task 4;
++count1;
}
count1=1;
while (count1<=20)
{
task 1;
count2=1;
while (count2<=5)
{
task 2;
++count2;
}
task 4;
++count1;
}
5-10
REMEMBER...
WHILE statement...
WHILE statement...
REMEMBER...
while (count1<=20);
while (count1<=20);
statement.
statement.
WHILE loop.
WHILE loop.
while (count1<=20)
task 1;
count2=1;
while (count1<=20)
task 1;
count2=1;
5-11
while (count1>0)
task 1;
count2=1;
while (count1>0)
task 1;
count2=1;
(like
(like
count1=1;
while (count1<=20)
{
task 1;
count2=1;
while (count2<=5)
{
task 2;
++count2;
}
task 4;
++count1;
count1=1;
while (count1<=20)
{
task 1;
count2=1;
while (count2<=5)
{
task 2;
++count2;
}
task 4;
++count1;
5-12
} .
} .
DOWHILE
DOWHILE
Statement
Statement
do
Condition is the requirement / prerequisite
{
to execute the tasks within the open
braces and close braces
task 1;
task 2;
} while (condition);
do
Condition is the requirement / prerequisite
{
to execute the tasks within the open
braces and close braces
task 1;
task 2;
} while (condition);
For example,
For example,
5-13
5-13
REMEMBER...
count1 = 1;
do
{
task 1;
task 2;
++count1;
} while (count1<=10);
count1 = 1;
do
{
task 1;
task 2;
++count1;
} while (count1<=10);
REMEMBER...
count1 = 1;
do;
count1 = 1;
do;
5-14
DOWHILE statement.
DOWHILE statement.
The misplaced of
DOWHILE statement.
DOWHILE statement.
count1 = 30;
do
{
task 1;
task 2;
++count1;
} while (count1>10);
3. Place
The misplaced of
count1 = 30;
do
{
task 1;
task 2;
++count1;
} while (count1>10);
(like
(like
semicolon
after
WHILE
statement
for
DOWHILE loop.
3. Place
semicolon
statement
for
} while (count1>10);
missing ; .
missing ; .
WHILE
DOWHILE loop.
} while (count1>10);
after
5-15
Outcome 6
Outcome 6
Selection Control
Selection Control
Structures
Structures
Module
Module
Objectives
Objectives
o Nested if statement
o Nested if statement
o If.else statement
o If.else statement
6-1
IF Statement
If statement
If statement
Ifelse statement
Ifelse statement
Ifelse if statement
Ifelse if statement
Condition is the
requirement /
prerequisite to
execute the tasks
IF Statement
Condition is the
requirement /
prerequisite to
execute the tasks
6-2
REMEMBER...
REMEMBER...
condition.
condition.
6-3
Multiple IF
For example,
Multiple IF
For example,
Statement
if (condition1)
{
task 1 ;
task 2;
}
if ( condition2)
{
task 3 ;
task 4 ;
}
Statement
if (condition1)
{
task 1 ;
task 2;
}
if ( condition2)
{
task 3 ;
task 4 ;
}
Nested IF
statement
statement
For example,
Nested IF
Statement
For example,
Statement
if (condition1)
{
task 1 ;
if ( condition2)
{
task 2 ;
task 3 ;
}
if (condition1)
{
task 1 ;
if ( condition2)
{
task 2 ;
task 3 ;
}
task 4;
}
task 4;
}
statement
statement
IF-ELSE
IF-ELSE
Statement
Statement
statement(s) to be executed.
statement(s) to be executed.
6-4
if (condition1)
{
task 1 ;
task 2;
}
else
{
task 3;
task 4;
}
task 5;
if (condition1)
{
task 1 ;
task 2;
}
else
{
task 3;
task 4;
}
task 5;
statement.
statement.
6-5
Relational
Relational
Operators and
Operators and
Simple Predicates
Simple Predicates
1. Equal-to, ==
1. Equal-to, ==
2. Not-equal-to, !=
2. Not-equal-to, !=
3. Less-than, <
3. Less-than, <
4. Less-than-or-equal-to, <=
4. Less-than-or-equal-to, <=
5. Greater-than, >
5. Greater-than, >
6. Greater-than-or-equal-to, >=
6. Greater-than-or-equal-to, >=
Logical
Logical
expressions and
expressions and
operators
operators
complex predicates:
complex predicates:
2. Logical or (disjunction)
2. Logical or (disjunction)
6-6
Operand_1 Operand_2
Operand_1 Operand_2
true
true
true
true
true
true
true
false
false
true
false
false
false
true
false
false
true
false
false
false
false
false
false
false
Operand_1 Operand_2
Operand_1 or Operand _2
Operand_1 Operand_2
Operand_1 or Operand _2
true
true
true
true
true
true
true
false
true
true
false
true
false
true
true
false
true
true
false
false
false
false
false
false
or interpretation.
or interpretation.
2. Logical or is represented by ||
2. Logical or is represented by ||
Nested IF-ELSE
Nested IF-ELSE
Statement
Statement
6-7
REMEMBER...
For example,
For example,
If (condition1)
{
task 1;
if (condition2)
{
task 2;
task 3;
}
else
{
task 4;
task 5;
}
If (condition1)
{
task 1;
if (condition2)
{
task 2;
task 3;
}
else
{
task 4;
task 5;
}
REMEMBER...
false.
false.
ELSE statement.
ELSE statement.
6-8
outside IF statement.
outside IF statement.
ELSE-IF
ELSE-IF
Statement
Statement
If (condition1)
{
task 1;
}
If (condition1)
{
task 1;
}
else if (condition2)
{
task 2;
task 3;
}
else if (condition2)
{
task 2;
task 3;
}
else if (condition 3)
{
task 4;
task 5;
}
else if (condition 3)
{
task 4;
task 5;
}
else
{
task 6;
}
else
{
task 6;
}
6-9
ELSE-IF statement.
ELSE-IF statement.
SWITCH and
SWITCH and
BREAK
BREAK
Statement
Statement
or an expression.
or an expression.
switch ( variable)
{
case constant 1:
task1;
break;
case constant 2:
task3;
break;
default:
task5 ;
break;
}
switch ( variable)
{
case constant 1:
task1;
break;
case constant 2:
task3;
break;
default:
task5 ;
break;
}
6-10
For example,
For example,
switch ( choice )
{
case 1:
printf (You have selected choice 1);
break;
case 2:
printf (You have selected choice 2);
break;
default:
printf (You have selected other choices);
break;
}
switch ( choice )
{
case 1:
printf (You have selected choice 1);
break;
case 2:
printf (You have selected choice 2);
break;
default:
printf (You have selected other choices);
break;
}
SWITCHBREAK statement.
SWITCHBREAK statement.
enclosed in parentheses.
enclosed in parentheses.
3. Enclosed in braces:
3. Enclosed in braces:
6-11
the statements in that case clause are executed until the end
the statements in that case clause are executed until the end
SWITCH statement.
SWITCH statement.
Limitation of
Limitation of
SWITCH and
SWITCH and
BREAK
BREAK
statement
statement
REMEMBER...
The SWITCH statement can test only for equality, and the
The SWITCH statement can test only for equality, and the
a range of values.
a range of values.
REMEMBER...
declaration.
declaration.
6-12
colon is ignored.
colon is ignored.
Example 1
CASE.
CASE.
Example 1
quadratic equation.
quadratic equation.
6-13
Summary
Summary
Style
Style
consideration
consideration
when using
when using
multiway selection
multiway selection
structure
structure
complex predicates.
complex predicates.
5. Use
proper
indentation
in
forming
SWITCH
5. Use
proper
indentation
in
forming
SWITCH
6-14
Summary
Summary
duplication
of
similar
actions
to
several
as
duplication
of
similar
actions
to
several
switch(major code)
{
case 1:
printf(Science student);
break;
switch(major code)
{
case 1:
printf(Science student);
break;
case 2:
case 2:
printf(Art student);
break;
printf(Art student);
break;
case 3:
case 3:
printf(Science student);
break;
printf(Science student);
break;
case 4:
case 4:
printf(Art student);
break;
printf(Art student);
break;
case 5:
case 5:
printf(Science student);
break;
printf(Science student);
break;
}
/* end switch */
}
/* end switch */
6-15
Summary
Summary
case 2:
case 4:
case 2:
case 4:
printf(Art student);
break;
printf(Art student);
break;
}
/* end switch */
}
/* end switch */
6-16
Outcome 7
Outcome 7
Character String
Character String
Definition of an array
Definition of an array
1-Dimensional array
1-Dimensional array
2-Dimensional array
2-Dimensional array
Pointers
Pointers
Declaration of Pointers
Declaration of Pointers
Pointers Arithmetic
Pointers Arithmetic
Character String
Character String
Definition
Definition
What is an
What is an
Array?
Array?
Advantages of
Array
Advantages of
Array
General
General
Introduction of
Introduction of
Array
Array
x[0]
x[1]
x[2]
x[3]
x[4]
x[5]
x[0]
x[1]
x[2]
x[3]
x[4]
x[5]
80
90
45
30
14
19
80
90
45
30
14
19
1-Dimensional Array
1-Dimensional Array
1-Dimensional
The array declaration specifies the type for the array and the
1-Dimensional
The array declaration specifies the type for the array and the
array
array
type_specifier array_name[size];
type_specifier array_name[size];
REMEMBER...
REMEMBER...
array if is not.
array if is not.
1-Dimensional Array
1-Dimensional Array
1-Dimensional
1-Dimensional
Array
Array
Initialization
Initialization
REMEMBER...
REMEMBER...
a = buffer [ i ] - buffer [ j ];
a = buffer [ i ] - buffer [ j ];
1-Dimensional Array
1-Dimensional Array
change the array index inside the square bracket. Thus, each
change the array index inside the square bracket. Thus, each
building.
building.
1-Dimensional Array
1-Dimensional Array
2-Dimensional Array
Overview
2-Dimensional Array
Overview
column number.
column number.
The array declaration specifies the type of the array and the
The array declaration specifies the type of the array and the
2-Dimensional Array
Example of 2-dimensional array declarations:
2-Dimensional Array
Example of 2-dimensional array declarations:
50
30
24
16
50
30
24
16
2-Dimensional Array
REMEMBER...
2-Dimensional Array
REMEMBER...
array.
array.
array.
initialization.
initialization.
2-dimensional
2-dimensional
array Processing
Dimensional array:
array Processing
Dimensional array:
bracket.
bracket.
2-Dimensional Array
2-Dimensional Array
The first FOR loop refers to the row of the array and second
The first FOR loop refers to the row of the array and second
Examples
Example 1
Examples
Write a program that determines the sum of multiple arrays.
Example 1
multiple arrays.
array.
array.
Example 2
array.
array.
After the data entry, the program will sort the data
array
After the data entry, the program will sort the data
keyed in by the user in descending order.
Example 3
multiple arrays.
descending order.
array.
array.
Pointers
Introduction
Pointers
A pointer is a variable whose value is the address or
Introduction
Pointer
Purpose of using
Pointer
Function of pointer
Function of pointer
Pointers
Pointers
Pointer
Pointer
declaration
data type such as int, char or double and use the indirection
declaration
data type such as int, char or double and use the indirection
operator *, as it prefix.
operator *, as it prefix.
Here is an example:
Here is an example:
int *pointer_to_margaret;
int *pointer_to_margaret;
int.
int.
Initializing
Initializing
Pointer variables
Pointer variables
2. an address; OR
2. an address; OR
For example:
For example:
pointer_to_margaret = NULL;
pointer_to_margaret = NULL;
pointer_to_margaret = 0;
pointer_to_margaret = 0;
pointer_to_margaret = &margaret;
pointer_to_margaret = &margaret;
Pointers
Input & Output
Input
format
Pointers
Input & Output
Input
format
Output
Unary operator
Summary
Unary operator
Summary
Pointers
Pointers
variable, v
array.
array.
Pointers
Pointers
Function
Function
Pointers
Pointers
Pointers
Function with pointer
Pointers
Function with pointer
Character Strings
Character Strings
Character
Character
constant &
constant &
character string
character string
character array.
character array.
Strings
Strings
length of a string.
length of a string.
#include <stdio.h>
#include <stdio.h>
int main()
{
char sentence[] = "Hello World";
int count = 0;
int i;
int main()
{
char sentence[] = "Hello World";
int count = 0;
int i;
Character Strings
Character Strings
any character.
any character.
Library Functions
Library Functions
for String
for String
Manipulation
Manipulation
integer.
integer.
strcpy
strcpy
main()
{
main()
{
char sent1[100], sent2 [100];
strcpy (sent1, sent2 )
:
strncpy
strncpy
Character Strings
strcmp
Character Strings
strcmp
Character Strings
Character Strings
strncmp
strncmp
strstr
strstr
Summary
This chapter at a
Summary
glance
This chapter at a
two-dimensional arrays.
glance
two-dimensional arrays.
elements.
elements.
functions.
functions.
Outcome 8
Outcome 8
Objective
C Functions
C Functions
o Function Definitions
o Function Definitions
o Function Declarations
o Function Declarations
o Function calls
o Function calls
and
declaring
with
o Defining
parameters
and
declaring
functions
with
parameters
value
value
8-1
Introduction to Structure
Introduction to Structure
Revision
int student[100] ;
Revision
int student[100] ;
(1-Dimensional
(1-Dimensional
Array)
Array)
Differences
single array.
STRUCTURE
8-2
Introduction to Structure
Revision (Array)
Introduction to Structure
Revision (Array)
of 100 students.
of 100 students.
8-3
Introduction to Structure
STRUCTURE
Declaration of STRUCTURE
Introduction to Structure
STRUCTURE
Declaration of STRUCTURE
declaration requires:
declaration requires:
8-4
Introduction to Structure
Introduction to Structure
Input
scanf(%s, student[1].name);
Input
scanf(%s, student[1].name);
manipulation of
scanf(%s,student[2].name);
manipulation of
scanf(%s,student[2].name);
STRUCTURE
STRUCTURE
scanf(%d, &student[1].batchno);
scanf(%d, &student[1].batchno);
scanf(%d, &student[2].batchno);
scanf(%d, &student[2].batchno);
scanf(%f,&student[1].CGPA);
scanf(%f,&student[1].CGPA);
scanf(%f,&student[2].CGPA);
scanf(%f,&student[2].CGPA);
Output
printf(%s, student[1].name);
Output
printf(%s, student[1].name);
manipulation of
printf(%s,student[2].name);
manipulation of
printf(%s,student[2].name);
STRUCTURE
printf(%d, student[1].batchno);
STRUCTURE
printf(%d, student[1].batchno);
printf(%d, student[2].batchno);
printf(%d, student[2].batchno);
printf(%f,student[1].CGPA);
printf(%f,student[1].CGPA);
printf(%f,student[2].CGPA);
printf(%f,student[2].CGPA);
Declaring Nested
Declaring Nested
STRUCTURE
including
STRUCTURE
including
another
STRUCTURE
variable.
Such
another
STRUCTURE
variable.
Such
below.
below.
struct faculty_name
{
char last_name_initial;
char last_name_initial;
};
/* end struct faculty_name */
struct faculty_name
{
char last_name_initial;
char last_name_initial;
};
/* end struct faculty_name */
We can then use this structure type and rewrite the structure
We can then use this structure type and rewrite the structure
declaration.
declaration.
8-5
Introduction to Structure
Introduction to Structure
struct faculty
{
int faculty_idno;
struct faculty_name name_initials;
int age;
char sex;
float salary;
};
/* end struct faculty */
struct faculty
{
int faculty_idno;
struct faculty_name name_initials;
int age;
char sex;
float salary;
};
/* end struct faculty */
STRUCTURE type.
STRUCTURE type.
struct faculty
{
int faculty_idno;
struct
{
char last_name_initial;
char first_name_initial;
} name_initials;
/*end struct */
struct faculty
{
int faculty_idno;
struct
{
char last_name_initial;
char first_name_initial;
} name_initials;
/*end struct */
int age;
char sex;
float salary;
};
/* end struct faculty */
int age;
char sex;
float salary;
};
/* end struct faculty */
8-6
Introduction to Structure
Introduction to Structure
Advantage of
Advantage of
STRUCTURE
STRUCTURE
REMEMBER...
REMEMBER...
of STRUCTURE
STRUCTURE
STRUCTURE
within
struct particular {
char name[100];
int studentID;
float CGPA;
};
within
struct particular {
char name[100];
int studentID;
float CGPA;
};
STRUCTURE
STRUCTURE
struct HND {
int batchno;
int no_of_student_EE;
int no_of_student_MM;
struct particular EE_student[5];
struct particular MM_student[5];
}batch[10];
struct HND {
int batchno;
int no_of_student_EE;
int no_of_student_MM;
struct particular EE_student[5];
struct particular MM_student[5];
}batch[10];
Manipulation of
Manipulation of
STRUCTURE
STRUCTURE
within
scanf("%d",&batch[1].EE_student[1].studentID);
STRUCTURE
within
scanf("%d",&batch[1].EE_student[1].studentID);
STRUCTURE
scanf("%s",batch[1].EE_student[1].name);
scanf("%s",batch[1].EE_student[1].name);
scanf("%f",&batch[1].EE_student[1].CGPA);
scanf("%f",&batch[1].EE_student[1].CGPA);
8-7
Introduction to Structure
REMEMBER
Introduction to Structure
REMEMBER
structure .
8-8
Function
Modular Design
Function
A variable strategy to break down the complex program into
Modular Design
program.
program.
Advantages of
Easier to develop.
Advantages of
Easier to develop.
modular design
modular design
Requirements for
modules
Requirements for
modules
point.
point.
Function
Function
definitions
definitions
of
of
1. a function type
1. a function type
2. a function name
2. a function name
parentheses
4. a compound statements; function body
parentheses
4. a compound statements; function body
8-9
Function
Function
Syntax of header
Syntax of header
Example of header
Example of header
Function Body
Function Body
Return to the
calling function
without taking
any data
Return to the
calling function
without taking
any data
Invoking a
Invoking a
function
function
8-10
Function
Control flow
between calling
and called
function
return; }
Function
Control flow
between calling
and called
function
return; }
main( )
{
int x, y z, total, largest;
max (total)
..
}
main( )
{
int x, y z, total, largest;
max (total)
..
}
8-11
Function
Function
return (largest);
}
return (largest);
}
main( )
{
int x [100], y[100][100],z ;
result=max ( x , y , z);
..
}
main( )
{
int x [100], y[100][100],z ;
result=max ( x , y , z);
..
}
8-12
Function
Function
Functions that
Functions that
return values
return only one value, we can use the function name for this
return values
return only one value, we can use the function name for this
The return type is any data type, such as int, double, or char,
The return type is any data type, such as int, double, or char,
that C supports.
that C supports.
return a value under its name, its return type must be void.
return a value under its name, its return type must be void.
Function with
Function with
parameters
parameters
its task, the called function may pass data back to the calling
its task, the called function may pass data back to the calling
3. by using parameters
3. by using parameters
8-13
Function
Function
Use a global
Use a global
variables between
variables between
functions
/* Global variables: */
int i; double j; int k;
functions
/* Global variables: */
int i; double j; int k;
void main()
{
void main()
{
Use of parameters
Use of parameters
between functions
between functions
memory
memory
location
for
the
corresponding
formal
location
for
the
corresponding
formal
function.
function.
8-14
Calling Functions
Function
Function
against
against
inadvertent
alterations.
Hence,
whenever
inadvertent
alterations.
Hence,
whenever
Calling Functions
By Value
By Value
By Reference
By Reference
By Value
By Value
Eg
Eg
void main()
{
int a,b;
a=1;
b=2;
addition(a,b);
printf(In void main(), a and b are %d and %d,a,b);
}
void main()
{
int a,b;
a=1;
b=2;
addition(a,b);
printf(In void main(), a and b are %d and %d,a,b);
}
8-15
Function
Function
By Reference
By Reference
Eg:
Eg:
void main()
{
int a,b;
a=1;
b=2;
addition(a,b);
printf(In void main(), a and b are %d and %d,a,b);
}
void main()
{
int a,b;
a=1;
b=2;
addition(a,b);
printf(In void main(), a and b are %d and %d,a,b);
}
8-16
Summary
This chapter at a
Summary
glance
This chapter at a
glance
different types.
different types.
We
studied
STRUCTURE
type
and
variable
studied
STRUCTURE
type
and
variable
We
recommended.
recommended.
expressions.
expressions.
8-17
Appendix
Appendix
auto
extern
static
auto
extern
static
break
float
struct
break
float
struct
case
for
switch
case
for
switch
char
goto
union
char
goto
union
const
if
unsigned
const
if
unsigned
continue
int
void
continue
int
void
default
long
volatile
default
long
volatile
do
registertypedef
while
do
registertypedef
while
double
return
signed
double
return
signed
else
short
sizeof
else
short
sizeof
enum
enum
Remarks
Remarks
All programs included in this appendix are tested using Microsoft Visual C/C++ 6.0
The project type used is Win32 Console Application
o File > New > Projects > Win32 Console Application
o Type in the project name and indicate the location
o Select A simple application
If these programs were to run on other C compilers; they may not be able to run as
expected because of different libraries are required/included to support the compilation
o If want the programs to be portable between different compilers, some
modification may desire
All programs included in this appendix are tested using Microsoft Visual C/C++ 6.0
The project type used is Win32 Console Application
o File > New > Projects > Win32 Console Application
o Type in the project name and indicate the location
o Select A simple application
If these programs were to run on other C compilers; they may not be able to run as
expected because of different libraries are required/included to support the compilation
o If want the programs to be portable between different compilers, some
modification may desire
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Variable declaration */
int a, b, c;
/* Variable declaration */
int a, b, c;
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Print out the string on screen */
printf("This program is to observe the function of printf command\n");
printf("The printf function is under the usage of literal text\n");
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Variable declaration */
char c;
int a;
float b;
/* Variable declaration */
char c;
int a;
float b;
The function of this program is to receive a character, float number and integer number from the
keyboard (key in by the user) and place them into their respective memorys location called c, b
and a. The last three printf statements are to display the content inside the variable a, b and c.
This is to ensure that the data received is being stored into the respective location. If the data
received are successfully stored into their respective location, the data display out using the
printf command should be similar as the data key in by the user.
The function of this program is to receive a character, float number and integer number from the
keyboard (key in by the user) and place them into their respective memorys location called c, b
and a. The last three printf statements are to display the content inside the variable a, b and c.
This is to ensure that the data received is being stored into the respective location. If the data
received are successfully stored into their respective location, the data display out using the
printf command should be similar as the data key in by the user.
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Variable declaration */
int
number1;
long
number2;
unsigned int number3;
unsigned short number4;
unsigned long number5;
/* Variable declaration */
int
number1;
long
number2;
unsigned int number3;
unsigned short number4;
unsigned long number5;
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
/* Prompt, read and print the unsigned short integer value of number4 */
printf("Please enter any unsigned short decimal integer : ");
scanf ("%u", &number4);
printf("The unsigned short decimal integer you entered is %u\n", number4);
/* Prompt, read and print the unsigned short integer value of number4 */
printf("Please enter any unsigned short decimal integer : ");
scanf ("%u", &number4);
printf("The unsigned short decimal integer you entered is %u\n", number4);
printf("\n");
printf("\n");
/* Prompt, read and print the unsigned long integer value of number5 */
printf("Please enter any unsigned long decimal integer : ");
scanf ("%lu", &number5);
printf("The unsigned long decimal integer you entered is %lu\n", number5);
/* Prompt, read and print the unsigned long integer value of number5 */
printf("Please enter any unsigned long decimal integer : ");
scanf ("%lu", &number5);
printf("The unsigned long decimal integer you entered is %lu\n", number5);
printf("\n");
printf("\n");
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Variable declaration */
char a;
char b[20];
/* Variable declaration */
char a;
char b[20];
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Variable declaration */
signed char b;
unsigned char a;
/* Variable declaration */
signed char b;
unsigned char a;
Step 1 : Enter (press ALT+254), the output will display 254 if a is declared as unsigned char.
Step 1 : Enter (press ALT+254), the output will display 254 if a is declared as unsigned char.
Step 3 : Enter (press ALT+254), the output will display -2 if once a is declared as signed
char.
Step 3 : Enter (press ALT+254), the output will display -2 if once a is declared as signed
char.
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Variable declaration */
int number1, number2;
/* Variable declaration */
int number1, number2;
10
10
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Variable declaration */
int number = 10;
/* Variable declaration */
int number = 10;
/* Plus 5 to number */
number += 5;
/* Print out the value of number */
printf("Value of number added by 5 is %d\n\n", number);
/* Plus 5 to number */
number += 5;
/* Print out the value of number */
printf("Value of number added by 5 is %d\n\n", number);
/* Subtract 3 to number */
number -= 3;
/* Print out the value of number */
printf("Value of number subtracted by 3 is %d\n\n", number);
/* Subtract 3 to number */
number -= 3;
/* Print out the value of number */
printf("Value of number subtracted by 3 is %d\n\n", number);
/* Multiply by 3 to number */
number *= 3;
/* Print out the value of number */
printf("Value of number multiplied by 3 is %d\n\n", number);
/* Multiply by 3 to number */
number *= 3;
/* Print out the value of number */
printf("Value of number multiplied by 3 is %d\n\n", number);
/* Divide by 3 to number */
number /= 3;
/* Print out the value of number */
printf("Value of number divided by 3 is %d\n\n", number);
/* Divide by 3 to number */
number /= 3;
/* Print out the value of number */
printf("Value of number divided by 3 is %d\n\n", number);
11
11
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main function */
/* Main function */
main()
{
main()
{
/* Variable declaration */
int y, i = 3;
/* Variable declaration */
int y, i = 3;
y = i++;
y = i++;
i = 3;
printf("\n\n");
i = 3;
printf("\n\n");
12
12
y = ++i;
y = ++i;
From the above example, the command of i++ and ++i does not make any differences if the
assignment operator is not involved. If the assignment operator involves, such as y = i++ and y =
++i; there is a difference between the use of ++i or i++. The differences are listed above.
From the above example, the command of i++ and ++i does not make any differences if the
assignment operator is not involved. If the assignment operator involves, such as y = i++ and y =
++i; there is a difference between the use of ++i or i++. The differences are listed above.
13
13
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Main Function */
/* Main Function */
main()
{
main()
{
/* Variable declaration */
int count1, b;
/* Variable declaration */
int count1, b;
/* Go to a new line */
printf("\n");
/* Go to a new line */
printf("\n");
}
14
14
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Main Function */
/* Main Function */
main()
{
main()
{
/* Variable declaration */
int count1, count3 = 2, count4 = 1;
/* Variable declaration */
int count1, count3 = 2, count4 = 1;
printf("\n\n\n");
printf("\n\n\n");
15
15
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Main Function */
/* Main Function */
main()
{
main()
{
/* Variable declaration */
int count1, count2, b;
/* Variable declaration */
int count1, count2, b;
/* Go to a new line */
printf("\n");
/* Go to a new line */
printf("\n");
}
16
16
}
/* Space for 3 lines */
printf("\n\n\n");
17
17
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Main Function */
/* Main Function */
main()
{
main()
{
/* Variable declaration */
int count1, b ;
/* Variable declaration */
int count1, b ;
/* Go to a new line */
printf("\n");
/* Go to a new line */
printf("\n");
}
18
18
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Main Function */
/* Main Function */
main()
{
main()
{
/* Variable declaration */
int count1, count2, b;
/* Variable declaration */
int count1, count2, b;
/* Go to a new line */
printf("\n");
/* Go to a new line */
printf("\n");
b = 2 * count2;
b = 2 * count2;
20
20
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Include directives */
#include "stdafx.h"
#include <stdio.h>
/* Main Function */
/* Main Function */
main()
{
main()
{
/* Variable declaration */
int count1, b;
/* Variable declaration */
int count1, b;
/* Go to a new line */
printf("\n");
/* Go to a new line */
printf("\n");
do
{
do
{
/* Add up the value of count1 with 2 then assign to b */
b = count1 + 2;
/* Print out the values of b in each loop */
printf("Loop %d : The value of count1 is %d\n", count1, b);
/* Increase the value of count1 */
++count1;
}
21
21
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main function
// Main function
main()
{
main()
{
// Variable declaration
float ass_1, ass_2, ass_3, average;
// Variable declaration
float ass_1, ass_2, ass_3, average;
22
22
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main function
// Main function
main()
{
main()
{
// Variable declaration
float ass_1, ass_2, ass_3, average;
// Variable declaration
float ass_1, ass_2, ass_3, average;
23
23
24
24
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main function
// Main function
main()
{
main()
{
// Variable declarations
float ass_1, ass_2, ass_3, average;
char competent;
// Variable declarations
float ass_1, ass_2, ass_3, average;
char competent;
25
25
26
26
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Variable declaration
float ass1, ass2, ass3, average;
char competent;
// Variable declaration
float ass1, ass2, ass3, average;
char competent;
27
27
printf("\n\n\n");
printf("\n\n\n");
28
28
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Variable declaration
float mark;
// Variable declaration
float mark;
// Read in a mark
printf("Please enter your mark : ");
scanf ("%f", &mark);
// Read in a mark
printf("Please enter your mark : ");
scanf ("%f", &mark);
29
29
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Variable declaration
float mark;
// Variable declaration
float mark;
// Read in a mark
printf("Please enter your mark : ");
scanf ("%f", &mark);
// Read in a mark
printf("Please enter your mark : ");
scanf ("%f", &mark);
30
30
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Variable declaration
int choice;
// Variable declaration
int choice;
switch(choice)
{
switch(choice)
{
31
31
32
32
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Variable declaration
int choice;
// Variable declaration
int choice;
switch(choice)
{
switch(choice)
{
33
33
34
34
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Array Variable declaration
int buffer[5] = {50, 20, 30, 98, 71};
printf("\n\n");
printf("\n\n");
35
35
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Array Variable declaration
int buffer[5];
printf("\n\n");
printf("\n\n");
36
36
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Variable declaration
int buffer[5], i = 2, j = 4, answer;
// Variable declaration
int buffer[5], i = 2, j = 4, answer;
}
37
37
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Variable declaration
int table[100], number, i;
// Variable declaration
int table[100], number, i;
printf("\n\n\n");
printf("\n\n\n");
38
38
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Declaration of 2 - dimensional array with values initialized
int buffer[2][3] = {{50, 20, 30}, {1, 3, 5}};
printf("\n\n\n");
printf("\n\n\n");
39
39
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Array Variable declaration
int buffer[2][3];
printf("\n\n\n");
printf("\n\n\n");
}
40
40
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main Function
// Main Function
main()
{
main()
{
// Variable declaration
int buffer[2][3], k = 0, m = 1, n = 2, answer;
// Variable declaration
int buffer[2][3], k = 0, m = 1, n = 2, answer;
41
41
42
42
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Include directives
#include "stdafx.h"
#include <stdio.h>
// Main function
// Main function
main()
{
main()
{
// Variable declaration
int table[100][100], i, j;
// Variable declaration
int table[100][100], i, j;
printf("\n\n\n");
printf("\n\n\n");
}
43
43
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Function header */
/* Function header */
main()
{
main()
{
/* Variable declaration */
int number1, number2, number3;
/* Variable declaration */
int number1, number2, number3;
44
44
printf("\n\n\n");
printf("\n\n\n");
45
45
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Function header */
/* Function header */
main()
{
main()
{
/* Variable declaration */
int u = 45, v, *au, *pv;
/* Variable declaration */
int u = 45, v, *au, *pv;
46
46
47
47
Objective : To store the data into the required address / memory location.
Objective : To store the data into the required address / memory location.
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Function header */
/* Function header */
main()
{
main()
{
/* Variable declaration */
int *pv, temp;
/* Variable declaration */
int *pv, temp;
48
48
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Function header */
/* Function header */
main()
{
main()
{
/* Variable declaration */
int array1[10];
int count1;
/* Variable declaration */
int array1[10];
int count1;
printf("
X%d = ", count1);
scanf ("%d", &array1[count1]);
printf("
X%d = ", count1);
scanf ("%d", &array1[count1]);
}
49
49
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Function header */
/* Function header */
main()
{
main()
{
/* Variable declaration */
long array1[10];
int count1;
/* Variable declaration */
long array1[10];
int count1;
printf("
X%d = ", count1);
scanf ("%ld", &array1[count1]);
printf("
X%d = ", count1);
scanf ("%ld", &array1[count1]);
}
50
50
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
/* Sub-function header */
modify(int *p, int *r)
{
/* Sub-function header */
modify(int *p, int *r)
{
return;
return;
/* Function header */
/* Function header */
main()
{
main()
{
/* Variable declaration */
int a, b;
/* Variable declaration */
int a, b;
51
52
52
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
/* Function header */
/* Function header */
main()
{
main()
{
/* Variable declaration */
char sent[100];
/* Variable declaration */
char sent[100];
53
53
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
/* Include directive */
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
/* Function header */
/* Function header */
main()
{
main()
{
/* Variable declaration */
char sent1[100], sent2[100];
/* Variable declaration */
char sent1[100], sent2[100];
54
54
main()
{
main()
{
// Variable declaration
char *destination_string, source_string[100];
// Variable declaration
char *destination_string, source_string[100];
55
55
main()
{
main()
{
// Variable declarations
int count1, length;
char *source_string, destination_string[100];
// Variable declarations
int count1, length;
char *source_string, destination_string[100];
56
56
printf("\n\n\n");
printf("\n\n\n");
57
57
main()
{
main()
{
// Variable declaration
int count;
char sent_1[100], sent_2[100];
// Variable declaration
int count;
char sent_1[100], sent_2[100];
sent_1[count] = NULL;
sent_2[count] = NULL;
sent_1[count] = NULL;
sent_2[count] = NULL;
}
58
58
main()
{
main()
{
// Variable declaration
int result;
char sent_1[100], sent_2[100];
// Variable declaration
int result;
char sent_1[100], sent_2[100];
// Compare the strings of sent_1 and sent_2 and assign the value to result
result = strcmp(sent_1, sent_2);
// Compare the strings of sent_1 and sent_2 and assign the value to result
result = strcmp(sent_1, sent_2);
// Do if result is equal to 0
if (result == 0)
printf("\n\nFirst string and Second string are the same\n\n\n");
// Do if result is equal to 0
if (result == 0)
printf("\n\nFirst string and Second string are the same\n\n\n");
59
59
60
60
main()
{
main()
{
// Variable declaration
int result;
char *sent_1, string_1[100], *sent_2, string_2[100];
// Variable declaration
int result;
char *sent_1, string_1[100], *sent_2, string_2[100];
// Compare the string values between sent_1 and sent_2 and assign the
value to result
result = strcmp(sent_1, sent_2);
// Compare the string values between sent_1 and sent_2 and assign the
value to result
result = strcmp(sent_1, sent_2);
// Do if result is equal to 0
if (result == 0)
printf("\n\nFirst string and Second string are the same\n\n\n");
// Do if result is equal to 0
if (result == 0)
printf("\n\nFirst string and Second string are the same\n\n\n");
62
62
main()
{
main()
{
// Variable declaration
int result;
char *sent_1, string_1[100], *sent_2, string_2[100];
// Variable declaration
int result;
char *sent_1, string_1[100], *sent_2, string_2[100];
// Compare the first 4 characters of sent_1 and sent_2 and assign the
value to result
result = strncmp(sent_1, sent_2, 4);
// Compare the first 4 characters of sent_1 and sent_2 and assign the
value to result
result = strncmp(sent_1, sent_2, 4);
// Do if result is equal to 0
if (result == 0)
printf("\n\nFirst string and Second string are the same\n\n\n");
// Do if result is equal to 0
if (result == 0)
printf("\n\nFirst string and Second string are the same\n\n\n");
64
64
main()
{
main()
{
// Variable declaration
char *string_1 = "Borland International", *string_2 = "land", *ptr;
// Variable declaration
char *string_1 = "Borland International", *string_2 = "land", *ptr;
65
65
main()
{
main()
{
// Variable declaration
char string_1[100], string_2[100], *result;
// Variable declaration
char string_1[100], string_2[100], *result;
}
66
66
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
main()
{
main()
{
int student_batchno[10], count;
char student_name[10][100];
float student_CGPA[10];
fflush(stdin);
printf("\n");
fflush(stdin);
printf("\n");
system ("cls");
system ("cls");
67
67
printf("\n");
printf("\n");
printf("\n\n\n");
printf("\n\n\n");
68
68
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
struct HND
{
struct HND
{
char name[100];
int batchno;
float CGPA;
char name[100];
int batchno;
float CGPA;
} EE_student[10];
} EE_student[10];
main()
{
main()
{
int count;
int count;
fflush(stdin);
printf("\n");
fflush(stdin);
printf("\n");
69
69
system ("cls");
system ("cls");
printf("\n");
printf("\n");
printf("\n\n\n");
printf("\n\n\n");
70
70
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
struct HND
{
struct HND
{
char name[100];
int batchno;
float CGPA;
char name[100];
int batchno;
float CGPA;
} EE_student[10], MM_student[10];
} EE_student[10], MM_student[10];
main()
{
main()
{
int count;
int count;
printf("\n");
printf("\n");
fflush(stdin);
fflush(stdin);
71
71
system ("cls");
system ("cls");
printf("\n");
printf("\n");
printf("\n\n\n");
printf("\n\n\n");
72
72
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
struct database
{
struct database
{
char date[100];
int invoiceno[10];
float amount[10];
int no_of_invoice;
char date[100];
int invoiceno[10];
float amount[10];
int no_of_invoice;
} day[10];
} day[10];
main()
{
main()
{
int count_1, count_2, no_day;
fflush(stdin);
fflush(stdin);
printf("\n\nDate : ");
scanf ("%[^\n]", day[count_1].date);
printf("\n\nDate : ");
scanf ("%[^\n]", day[count_1].date);
73
73
printf("Amount
: ");
scanf ("%f", &day[count_1].amount[count_2]);
printf("Amount
: ");
scanf ("%f", &day[count_1].amount[count_2]);
printf("\n");
printf("\n");
system ("cls");
system ("cls");
printf("\n");
printf("\n");
printf("\n\n");
printf("\n\n");
printf("\n\n\n");
printf("\n\n\n");
}
}
}
}
}
}
74
74
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
struct database
{
struct database
{
char date[100];
int invoiceno[10];
float amount[10];
int no_of_invoice;
float total_amount;
char date[100];
int invoiceno[10];
float amount[10];
int no_of_invoice;
float total_amount;
} day[10];
} day[10];
main()
{
main()
{
int count_1, count_2, no_day;
fflush(stdin);
fflush(stdin);
day[count_1].total_amount = 0;
day[count_1].total_amount = 0;
printf("\n\nDate : ");
scanf ("%[^\n]", day[count_1].date);
printf("\n\nDate : ");
scanf ("%[^\n]", day[count_1].date);
75
75
printf("Amount
: ");
scanf ("%f", &day[count_1].amount[count_2]);
printf("Amount
: ");
scanf ("%f", &day[count_1].amount[count_2]);
day[count_1].total_amount += day[count_1].amount[count_2];
day[count_1].total_amount += day[count_1].amount[count_2];
printf("\n");
printf("\n");
printf("\n\n");
printf("\n\n");
system ("cls");
system ("cls");
printf("\n");
printf("\n");
printf("\n\n\n");
printf("\n\n\n");
76
76
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
struct particular
{
struct particular
{
char name[100];
int studentID;
float CGPA;
char name[100];
int studentID;
float CGPA;
};
};
struct HND
{
struct HND
{
int batchno;
int no_of_EE_student;
int no_of_MM_student;
struct particular EE_student[5];
struct particular MM_student[5];
int batchno;
int no_of_EE_student;
int no_of_MM_student;
struct particular EE_student[5];
struct particular MM_student[5];
} batch[10];
} batch[10];
main()
{
main()
{
int count_1, count_2, batch_total;
77
77
{
printf("\n\nBatch No. : ");
scanf ("%d", &batch[count_1].batchno);
fflush(stdin);
fflush(stdin);
{
fflush(stdin);
fflush(stdin);
printf("\nName
: ");
scanf ("%[^\n]", batch[count_1].EE_student[count_2].name);
printf("\nName
: ");
scanf ("%[^\n]", batch[count_1].EE_student[count_2].name);
printf("Student ID : ");
scanf ("%d", &batch[count_1].EE_student[count_2].studentID);
printf("Student ID : ");
scanf ("%d", &batch[count_1].EE_student[count_2].studentID);
printf("\n");
printf("\n");
printf("\n\n");
printf("\n\n");
system ("cls");
system ("cls");
printf("\n");
printf("\n");
printf("\n\n");
printf("\n\n");
printf("\n\n\n");
printf("\n\n\n");
79
79
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
struct time
{
struct time
{
};
};
struct machine
{
struct machine
{
int
number, sensor, cyclinder;
char
purpose[100];
char
robot_tupe;
struct time downtime;
int
number, sensor, cyclinder;
char
purpose[100];
char
robot_tupe;
struct time downtime;
} station[100];
} station[100];
main()
{
main()
{
int number, count, down[100];
80
80
printf("\nFunction of station %d
: ", station[count].number);
scanf ("%s", station[count].purpose);
printf("\nFunction of station %d
: ", station[count].number);
scanf ("%s", station[count].purpose);
printf("Downtime \n");
printf("hour : ");
scanf ("%d", &station[count].downtime.hour);
printf("minutes : ");
scanf ("%d", &station[count].downtime.minutes);
printf("seconds : ");
scanf ("%d", &station[count].downtime.seconds);
printf("Downtime \n");
printf("hour : ");
scanf ("%d", &station[count].downtime.hour);
printf("minutes : ");
scanf ("%d", &station[count].downtime.minutes);
printf("seconds : ");
scanf ("%d", &station[count].downtime.seconds);
printf("\n\n");
printf("\n\n");
system ("cls");
system ("cls");
printf("No. of sensors
: %d\n", station[count].sensor);
printf("No. of cyclinders : %d\n", station[count].cyclinder);
printf("Downtime
: %d hour %d minutes %d seconds\n",
station[count].downtime.hour,
station[count].downtime.minutes,
station[count].downtime.seconds);
printf("Downtime in second is %d\n", down[count]);
printf("No. of sensors
: %d\n", station[count].sensor);
printf("No. of cyclinders : %d\n", station[count].cyclinder);
printf("Downtime
: %d hour %d minutes %d seconds\n",
station[count].downtime.hour,
station[count].downtime.minutes,
station[count].downtime.seconds);
printf("Downtime in second is %d\n", down[count]);
printf("\n\n");
printf("\n\n");
printf("\n\n\n");
printf("\n\n\n");
82
82
Objective : To observe the control flow between the calling and called function
Objective : To observe the control flow between the calling and called function
#include "stdafx.h"
#include <stdio.h>
#include "stdafx.h"
#include <stdio.h>
main()
{
main()
{
int a = 2, b;
int a = 2, b;
modify (a);
modify (a);
printf("\n\n\n");
printf("\n\n\n");
b *= 3;
b *= 3;
return;
return;
}
83
83
Objective : To observe the control flow between the calling and called function for
multiple arguments
Objective : To observe the control flow between the calling and called function for
multiple arguments
#include "stdafx.h"
#include <stdio.h>
#include "stdafx.h"
#include <stdio.h>
main()
{
main()
{
int number_1 = 200, number_2 = 300, number_3 = 400;
printf("\n\n\n");
printf("\n\n\n");
printf("\n\n\n");
printf("\n\n\n");
84
84
return;
return;
85
85
#include "stdafx.h"
#include <stdio.h>
#include "stdafx.h"
#include <stdio.h>
main()
{
main()
{
int number_1 = 20, number_2 = 3, number_3 = 4, answer;
printf("\n\n\n");
printf("\n\n\n");
int final;
int final;
86
86
printf("\n\n\n");
printf("\n\n\n");
return (final);
return (final);
87
87
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
main()
{
main()
{
int count_1, count_2, array_1[100], array_2[100];
printf("\n\n\n");
printf("\n\n\n");
88
88
printf("\n\n\n");
printf("\n\n\n");
return (answer);
return (answer);
89
89
#include "stdafx.h"
#include <stdio.h>
#include "stdafx.h"
#include <stdio.h>
struct rect
{
struct rect
{
} a;
} a;
struct info
{
struct info
{
} b;
} b;
main()
{
main()
{
struct rect data;
struct info stru;
90
90
temp.x_1 += 3;
temp.x_2 += 3;
temp.x_1 += 3;
temp.x_2 += 3;
return (temp);
return (temp);
int y3;
int y3;
y3 = rec.y_1;
rec.y_1 = rec.y_2;
rec.y_2 = y3;
y3 = rec.y_1;
rec.y_1 = rec.y_2;
rec.y_2 = y3;
return (rec);
return (rec);
}
91
91
#include "stdafx.h"
#include <stdio.h>
#include "stdafx.h"
#include <stdio.h>
struct rect
{
struct rect
{
};
};
main()
{
main()
{
struct rect data;
struct rect rec;
data = get();
data = get();
rec = print();
rec = print();
92
92
printf("------------------------------------\n");
printf("rec.x_1 = %d\n", rec.x_1);
printf("rec.x_2 = %d\n\n", rec.x_2);
printf("------------------------------------\n");
printf("rec.x_1 = %d\n", rec.x_1);
printf("rec.x_2 = %d\n\n", rec.x_2);
return (temp);
return (temp);
return (info);
return (info);
93
93
#include "stdafx.h"
#include <stdio.h>
#include "stdafx.h"
#include <stdio.h>
struct rect
{
struct rect
{
} a;
} a;
main()
{
main()
{
struct rect data;
struct rect stru;
}
94
94
return (temp);
return (temp);
return (info);
return (info);
95
95