Flowchart in C Language
Flowchart in C Language
What is a Flowchart?
A flowchart is a diagram that depicts the flow of a program. The figure shown here is a flowchart for the addition of two numbers.
START Display message Please enter two numbers Read two Numbers Calculate the Sum Display Sum END
Nihar Ranjan Roy 2
Symbol
Input/output
Output operation
Display Sum
END
Read operation
Accept the value and store them into variables Fno Sno
Display Sum
END
Processing /calculation
Processing/calculate Sum=Fno+Sno
Display Sum
END
Output
Display Sum
END
Sequence Structure
A series of actions are performed in sequence The addition of two numbers was a sequential activity
Decision Structure
One of two possible actions is taken, depending on a condition. A new symbol, the diamond, indicates a yes/no question. If the answer to the question is yes, the flow follows one path. If the answer is no, the flow follows another path
NO
YES
10
PROBLEM
11
Decision Structure
In the flowchart segment below, the question is x < y? is asked. If the answer is no, then process A is performed. If the answer is yes, then process B is performed.
NO x < y?
YES
Code in C
If (x<y) Square=y*y; Else Square=x*x;
Square=y*y Square=x*x
12
Repetition Structure A repetition structure represents part of the program that repeats. This type of structure is commonly known as a loop.
13
Repetition Structure
Notice the use of the diamond symbol. A loop tests a condition, and if the condition exists, it performs an action. Then it tests the condition again. If the condition still exists, the action is repeated. This continues until the condition no longer exists.
YES Condition?
No
14
Repetition Structure
In the flowchart segment, the question is x < y? is asked. If the answer is yes, then Process A is performed. The question is x < y? is asked again. Process A is repeated as long as x is less than y. When x is no longer less than y, the repetition stops and the structure is exited.
YES x < y?
Do some Processing
15
PROBLEM
16
Repetition Structure
The flowchart segment below shows a repetition structure expressed in C as a while loop.
i=0
Flowchart
YES
Print name i=i+1
C Code
i=0; while (i < 5) { puts(nihar Ranjan roy); i=i+1; }
Nihar Ranjan Roy 17
i< 5?
C Code
YES i< 5?
Print name
18
i < 5?
YES
Print name
i=i+1
19
Case Structure
One of several possible actions is taken, depending on the contents of a variable.
20
Case Structure
The structure below indicates actions to perform depending on the value in years_employed.
CASE years_employed
1
bonus = 100
2
bonus = 200
3
bonus = 400
Other
bonus = 800
21
Case Structure
1
bonus = 100
2
bonus = 200
3
bonus = 400
Other
bonus = 800
22
Connectors
Sometimes a flowchart will not fit on one page. A connector (represented by a small circle) allows you to connect two flowchart segments.
A
Nihar Ranjan Roy 23
Connectors
The A connector indicates that the second flowchart segment begins where the first segment ends.
START
END A
24
Modules
A program module (such as a function in C) is represented by a special symbol.
25
Modules
The position of the module symbol indicates the point the module is executed. A separate flowchart can be constructed for the module.
START
Read Input.
Display results.
END
26
Problem
Design an algorithm and flow chart for converting an integer number to its binary equivalent.
27