Professional Documents
Culture Documents
Use of a flowchart
Types of Flowcharts
Flowchart Symbols
Here is a chart for some of the common symbols used in drawing flowcharts.
Advantages of Flowchart
Disadvantages of Flowchart
Flowcharts are difficult to draw for large and complex programs.
It does not contain the proper amount of details.
Flowcharts are very difficult to reproduce.
Flowcharts are very difficult to modify.
Algorithm
Algorithm is a step – by – step procedure which is helpful in solving a
problem. If, it is written in English like sentences then, it is called as
‘PSEUDO CODE’.
Properties of an Algorithm
An algorithm must possess the following five properties −
Input
Output
Finiteness
Definiteness
Effectiveness
Example
Algorithm for finding the average of three numbers is as follows −
Start
Read 3 numbers a,b,c
Compute sum = a+b+c
Compute average = sum/3
Print average value
Stop
Step 1: Start
Step 4: If a > b
If a > c
Else
Else
If b > c
Display b is the largest number.
Else
Step 5: Stop
Step 1: Start
factorial ← 1
i ← 1
5.2: i ← i+1
Step 7: Stop
What is While Loop?
A While loop is the most straightforward looping structure. It is an
entry-controlled loop. In a while loop, a condition is evaluated before
processing a body of the loop. If a condition is true, then and only then
the body of a loop is executed.
After the body of a loop is executed, the control again goes back to
the beginning, and the condition is checked. If it is true, the same
process is executed until the condition becomes false. Once the
condition becomes false, the control goes out of the loop.
In a while loop, if the condition is not true, then the body of a loop will
not be executed, not even once.
Program to print table for the given number using do while loop
#include<stdio.h>
int main(){
int i=1,number=0;
printf("Enter a number: ");
scanf("%d",&number);
do{
printf("%d \n",(number*i));
i++;
}while(i<=10);
return 0;
}
Output
Enter a number: 5
5
10
15
20
25
30
35
40
45
50
Differences between while and do-while loop in C
While Do While
It checks the condition first and This loop will execute the
then executes statement(s) statement(s) at least once, then the
condition is checked.
While loop allows initialization of Do while loop allows initialization of
counter variables before starting counter variables before and after
the body of a loop. starting the body of a loop.
It is an entry controlled loop. It is an exit controlled loop.
We do not need to add a We need to add a semicolon at the
semicolon at the end of a while end of the while condition.
condition.
In case of a single statement, we Brackets are always needed.
do need to add brackets.
In this loop, the condition is The loop condition is specified after
mentioned at the starting of the the block is executed.
loop.
Statement(s) can be executed Statement is executed at least once.
zero times if the condition is false.
Syntax: Syntax:
while (condition) { do{
Statements; // loop body Statements; //loop body
} } while (condition);