Unit-1: CO-1: Prepare Flowchart and Algorithm For Real Life Problem
Unit-1: CO-1: Prepare Flowchart and Algorithm For Real Life Problem
DU # 2304CS101
Unit-1
Introduction
CO-1: prepare flowchart and
algorithm for real life problem
Parallelog
Oval Rectangle
ram
Arro
Diamo Connect
ws
nd or
1 Oval
2 Parallelog
ram
Parallelogram represents input or output in the flowchart.
When we want to take any value from user during the process; to indicate
that step we will use parallelogram. It will be known as INPUT.
When we want to show any value during the process; to indicate that step
we will use parallelogram. It will be known as OUTPUT.
3 Rectang
le
Rectangle represents process for the flowchart.
When we want show any step/calculation/logic in the process at that time
we will use this rectangle in the flowchart.
4 Diamond
5 Connector
This symbol indicates that the flow continues where a matching symbol
has been placed.
When we are drawing a flowchart and reach the bottom of the page or
need to jump to another page, draw a connector symbol and connect it to
the last item on the flowchart.
6 Arrow
When we want to join/connect two symbols at that time we can use arrow
symbol.
When we want show the flow direction in flowchart at that time we can
also use respective arrow symbol.
• Easy to show branching and looping. • Difficult to show branching and looping.
• Flowchart for big problem is impractical. • Algorithm can be written for any type
problem.
Stop
Start
Step Start
Read 1:
value of Step Read value of no
no 2:
Step If no mod 2 , goto Step
3: =0 5
If no Step Print no is , goto
YES mod NO 4: odd Step 6
Step Print no is even
2= 5:
Step Stop
0
6:
Print no is Print no is
even odd
Stop
Prof. Ashok G. Badresiya #2304CS101 (CP-I) Unit 1 – Introduction 26
Example – 3
Draw flowchart and Write algorithm to find maximum number
from two numbers.
Start
Step Start
1:
Read a, b Step Read a, b
2:
Step If a > , goto
3: b Step 5
Step Print b is , goto
YES If NO 4: maximum Step 6
Step Print a is
a>b 5: maximum
Step Stop
6:
Print a is Print b is
maximum maximum
Stop
Increment count
by 2 Print
Stop
count count + sum
Prof. Ashok G. Badresiya
2 #2304CS101 (CP-I) Unit 1 – Introduction 30
Example – 7
Draw flowchart and Write algorithm to find maximum number
from three numbers.
Start
Step 1: Start
Read a, Step 2: Read a, b, c
b, c
Step 3: If a > b , goto
YES NO Step 7
If Step 4: If b > c , goto
a>b Step 6
Step 5: Print c is maximum
YES If NO NO YES
If Step 6: Print b is
a>c b>c maximum
Print a is Print c is Print b is Step 7: If a > c , goto Step 9
maximu maximu maximu Step 8: Print c is maximum
m m m
Step 9: Print a is
maximum
Step 10: Stop
Stop
Prof. Ashok G. Badresiya #2304CS101 (CP-I) Unit 1 – Introduction 31
Example – 8
Draw flowchart and Write algorithm to find factorial of the given
number.
Start Step 1: Start
Step 2: Read N
Read N
Step 3: Initialize count 1, fact
Initialize 1
Step 4: Repeat step 5 to step 6 until
count 1, fact count ≤ N
1 Step 5: calculate fact fact *
count
Step 6: count count +1
Is NO
count Step 7: print fact
≤N Step 8: Stop
YES
calculate
fact fact *
count
Increment count
by 1
count count + print fact Stop
Prof. Ashok G. Badresiya 1 #2304CS101 (CP-I) Unit 1 – Introduction 32
Introduction of
Programming
Section 3
Program
Program : a set of instruction which is written in any language which
computer can understand.
1. Modular Language:
Large program can be divided into small functions to reduce complexity.
2. Portable language:
Program written in one computer can be executed on another computer without any
modification.
3. Concise language:
There are only 32 keywords in C.
4. Datatypes:
Variety of data types are available for efficient and easy programming.
5. Operators:
Most of the possible operators for variety of operations are available.
6. Speedy Execution:
Execution of program is much faster than languages program.
7. Core Language:
We can write application software as well as system software in C. Also it is base of
many other programming languages.
High Low
Compiler
level level
Languag Languag
e e
Compila
tion
Error
• Display all errors after compilation, all at the • Displays error of each line one by one.
same time.
Keywo
rd
Identifi
String
er
C Tokens
Special
Consta
Operat nts
ors
Operat
ors
KEYWORDS
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
2.1.1 2.2.1
2.1.2
Array 2.2.2
Structure
2.1.3
Pointer 2.2.3
Union
Prof. Ashok G. Badresiya
Function
#2304CS101 (CP-I) Unit 1 – Introduction
Enum 57
1. Primary Data type
1.1
integer
Integer numbers are whole numbers without decimal point and fractional
part, e.g. 20, -154 etc.
Signed number can store positive or negative values. e.g. 20, -154.
Unsigned number means value can be only zero or positive. e.g. 20,
100, 0.
By default variable is signed.
-32768 to 0 to
int 2 2
32767 65535
-2,147,483,648 0 to
long int 4 to 4 4,294,967,
2,147,483,647 295
-32768 to 0 to
int 2 1 2 1
32767 65535
6 6
- 16- t 216- - 0 t 21 -
1 1 6
0 to 1
o
- 21 o1
2,147,483,64 0 to
1
3 3 - t 25 -
long int 4 2 8 to 4 2 4,294,96 5 65535
2,147,483,64 7,295 2 o 1
-32768 to
7
32767
1.2 float
Float numbers contain decimal point and fractional part, e.g. 3.25, 7.89, -
100.25, 10.00.
Precision means with how much accuracy required when we store digits
after decimal points. e.g. 3 then we can store up to 3 digits after decimal
point.
long
10 -279 to 279-1
double
2.1 Derived
2. Secondary Data type
Data type
2.2 User Defined
Data type
Poin
2.1 Derived Arr ter
Data type ay
Functi
on
Unio
2.2 User Defined Struct n
Data type ure
Enum
Constant
(Literal • String constant is a sequence of characters
s) enclosed within a double inverted comma.
• The characters may be letter, number,
1. Decimal (0-9) special character, blank space, etc..
(signed, • Non
Example: “darshan”, “university”,
unsigned) Numeric
Numeric
“2023”, “@s”
2. Octal (0-7) Constant
(signed, Constant
unsigned)
3. Hexadecimal (0-
9,A-F)
Float/
Integer Character String
Real
Constant Constant Constant
Constant
1. Decimal : 123,-79 • Single character enclosed within a pair of single
2. Octal : 127,-73 quote mark.
3. Hexadecimal : • Example: ‘a’, ‘p’,’P’, ‘Z’
9AB,Prof.
82F Ashok G. Badresiya #2304CS101 (CP-I) Unit 1 – Introduction 72
Backslash Constant
Back slash constants are a special type of character constant which
consists of two characters.
This is known as escape sequence. Escape sequence starts with backslash
‘\’ character.
Escape
Seque Meaning
nce
\0 End of string – NULL
\t Horizontal tab
.. .. .. .. .. .. .. .. ..
Thank
You