Algorithmsand Flowchart
Algorithmsand Flowchart
• Algorithms are the English like steps to solve a problem. It is the part
of software designing. Before creating a program or software we
develop its design using some tools like algorithms, Flowcharts etc.
• Mainly we follow following steps to design an algorithm.
Algorithm Program
Step 1: Start void main()
{
Step 2: Declare a,b,sum int a,b,sum;
Step 3: Print “ Enter value of a” printf(“ Enter value of a”);
Step 4: Input a scanf(“%d”, &a);
Step 5: Print “ Enter value of b” printf(“ Enter value of b”);
Output :
Enter value of a 10
Enter value of b 20
Sum = 30
Sample example
• Examples: Problem − Design an algorithm to add two numbers and
display the result.
step 1 − START
step 2 − declare three integers a, b & c
step 3 − define values of a & b
step 4 − add values of a & b
step 5 − store output of step 4 to c
step 6 − print c
step 7 − STOP
Flowchart
Sample examples
3. Write an algorithm and draw flowchart to add, sub, mul, div 2 numbers.
Algorithm Flowchart
Step 1: START
Step 2:DECLARE A, B, ADD,SUB,MUL,DIV
Step 3: INPUT A,B
Step 4: ADD A+B
Step 5: SUB A-B
Step 6: MUL A*B
Step 7: DIV A/B
Step 8: PRINT “SUM=“,ADD
Step 9:PRINT “SUB=“,SUB
Step 10:PRINT “MUL=“,MUL
Step 11:PRINT “DIV=“,DIV
Step 12:STOP
Sample examples
4. Write an algorithm and draw flowchart to find greatest among
two numbers. START
Algorithm
Step 1: START
Step 2:DECLARE A, B
DECLARE A,B
Step 3: INPUT A,B
Step 4: IF A>B THEN GOTO STEP 5 ELSE GOTO STEP 6
Step 5: PRINT “A IS GREATEST” GOTO 7
INPUT : A, B
Step 6: PRINT “B IS GREATEST”
Step 7: STOP
IF N
PRINT: B
A>B
IS BIG
then
Y
PRINT: A
IS BIG
STOP