Anda di halaman 1dari 23

Algorithms & Flowchart

Assignment
By
Al Mamun Parvez , Depta Paul, Al Amin ,Khairun Nahar Jinia .

Algorithms
What is Algorithm ?
A sequential solution of any program that written in human
language,called algorithm.
Algorithm is first step of the solution process, after the
analysis of problem, programmer write the algorithm of that
problem.
Asetofrulesforsolvingaprobleminafinitenumberofstep
s,asforfindingthegreatestcommondivisor.
Alogicalarithmeticalorcomputationalprocedurethatifcorr
ectly applied ensuresthesolutionofaproblem.

Steps in Program Solving


First produce a general algorithm (one can use
Pseudocode )
Refine the algorithm successively to get step by
step detailed algorithm that is very close to a
computer language.
Pseudocode is an artificial and informal language
that helps programmers develop algorithms
.Pseudocode is very similar to everyday English.

Example of Algorithms:
Q. Write a algorithm to find out number is odd or even?
step 1 : start
step 2 : input number
step 3 : rem=number mod 2
step 4 : if rem=0 then

print "number even

Else

print "number odd

endif

step 5 : stop

Flowchart

What is Flowchart ?
Graphical representation of any
program is called flowchart.
Pictorial representation of an
algorithm is called its flowchart.

The Flowchart
A Flowchart
Shows logic of an algorithm
Emphasizes individual steps and their
interconnections
e.g. control flow from one action to the
next.

Symbols of Flowchart
There are some standard graphics that are
used in flowchart as following:

Symbols of Flowchart

Symbols of Flowchart

A simple flowchart

Example of Flowchart:
Q. Make a flowchart to input temperature, if
temperature is less than 32 then print "below
freezing" otherwise print "above freezing"?

Example 1(Algorithms &


Flowchart )
Q.Write an algorithm and draw flowchart to find the
factorial value of a number also write the c program.
Algorithm:
step 1. Start
step 2. Read the number n
step 3. [Initialize]
i=1, fact=1

Example 1
step
step
step
step

4.
5.
6.
7.

Repeat step 4 through 6 until i=n


fact=fact*i
i=i+1
Print fact
step 8. Stop
[process finish of calculate the factorial value of a
number]

Example 1
Flowchartfor calculate factorial value of
a number:

Example 1
c program to find out factorial value of a number
#include<stdio.h>
#include<conio.h>
intmain()
{
intn,i,fact=1;
printf("Enter any number : ");
scanf("%d",&n);
for(i=1; i<=n; i++)
fact = fact * i;
printf("Factorial value of %d = %d",n,fact);
return0;
}

Example 2
Q.Convert temperature Fahrenheit to Celsius.
Algorithm:
Step1: Start
Step 2: Read Temperature in Fahrenheit F
Step 3: C 5/9*(F32)
Step 4: Print Temperature in Celsius: C
Step5: End

Example 2
Flowchart:

Example 3
Write an algorithm that reads two values, determines the
largest value and prints the largest value with an identifying
message.
ALGORITHM
Step 1: Input VALUE1, VALUE2
Step 2: if (VALUE1 > VALUE2) then
MAX= VALUE1
else
MAX= VALUE2
endif
Step 3: Print The largest value is, MAX

Example 3
Flowchart

if else Statement

If (condition)
{
block1;
}
else

Entry

False

Block2
block2;
}

Condition
?

Print

True

Block1

While Loop Statement


While(test condition)
{
body of the loop
}

Entry

Loop Body

True

Test

Condition
False

For Loop Statement

For(initialization ; test-condition ; increment)


{
body of the loop
}

Entry

Test

Condition
True

Loop Body

False

Thank You