Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views16 pages

Examples of Algorithms and Flow Charts C

The document outlines the characteristics of algorithms, emphasizing that they must have a finite number of clear, ordered steps and produce at least one output. It also compares algorithms to flowcharts and programs, illustrating their similarities and differences through various examples and C code implementations for solving mathematical problems. Additionally, it highlights that different algorithms can have varying performance characteristics in terms of speed and memory usage.

Uploaded by

13857shtripti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views16 pages

Examples of Algorithms and Flow Charts C

The document outlines the characteristics of algorithms, emphasizing that they must have a finite number of clear, ordered steps and produce at least one output. It also compares algorithms to flowcharts and programs, illustrating their similarities and differences through various examples and C code implementations for solving mathematical problems. Additionally, it highlights that different algorithms can have varying performance characteristics in terms of speed and memory usage.

Uploaded by

13857shtripti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Algorithm characteristics

1. It should have finite number of steps. No one can be expected to execute infinite number of steps.
2. The steps must be in order and simple
3. Each step should be defined clearly stated i.e. without un-ambiguity (without doubtfulness)
4. Must include all required information
5. Should exhibit at least one output

Algorithm Flowchart Program


An algorithm is defined as A flowchart is pictorial Set of instructions. Instruction
sequence of steps to solve a (graphical) representation of is a command to the computer
problem (task). an algorithm. to do some task.

Algorithm can also be defined A picture is worth of 1000 Implementation of Algorithm


as a plan to solve a problem words. We can understand or flowchart
and represents its logic. more from picture than words.

Different algorithms have different performance characteristics to solve the same problem. Some
algorithms are fast. Some are slow. Some occupy more memory space. Some occupy less memory
space. Some are complex and some algorithms are simple.

Logically algorithm, flowchart and program are the same.


1|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
Examples of Algorithms and Flowcharts (with C code)

1. To find sum of two numbers


Algorithm Flowchart Program

Stop
1. Start
2. Read a, b
3. c = a + b
4. Print or display c
5. Stop
Start

Read a, b c = a + b Write c
2. Finding Area of the square
Algorithm Flowchart Program

Start
1. Start
2. Read length, L
3. area = L*L
4. Print or display area 5. Stop
Stop

Read L area = L*L

Write
area

2|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
3. Finding Area of the rectangle
Algorithm Flowchart Program

Start

1. Start
2. Read side length,
a 3. Read side
length b 4. area =
a*b
5. Print or display
area 6. Stop
Read a

Read b
area

area = a*b
Stop

Write

4. Area of a triangle where three sides are given


Algorithm Flowchart Program

Stop
1. Start
2. Read a, b, c
3. s = (a+b+c)/2
4. A=sqrt (s
*(s-a)*(s-b)*(s-c)) 5. Print
or display A
6. Stop
Start

Read a, b, c

s = (a+b+c)/2
A = sqrt
s(s-a)*(s-b)*(s-c)

Write
A

3|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
5. Find the area & perimeter of a square Algorithm
Flowchart Program

Print or display A,P


6. Stop
1. Start Start
2. Read length L 3.
Area A = L*L 4.
Perimeter P = 4*L 5. Read L
A, P

A = L*L P = 4*L
Stop

Write

6. Calculating

the average

for 3

numbers
Algorithm Flowchart

Program

1. Start
2. Read 3 numbers A, B, C
3. Calculate the average by
the equation:
Average = (A + B + C)/3
4. Print average
5. Stop

4|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
7. Greatest of two numbers
Algorithm Flowchart Program

1. Start
2. Read A,B
3. If A > B then
Print A
is large
else
Print B
is large
4. Stop

8. Interchange the value of two numbers


Algorithm Flowchart Program

1. Start
2. Read two values into two
variables a, b
3. Declare third variable, c
c=a
a=b
b=c
4. Print or display a, b
5. Stop
5|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
9. Calculate simple interest using the expression
(SI=PNR/100) Algorithm Flowchart Program

Start

1. Start
2. Read P, N, R
3. SI=(PNR)/100 4.
Print SI
5. Stop
Read P, N, R

SI = (P*N*R)/100

Write
SI

Stop

10. Convert temperature from Fahrenheit to Celsius


Algorithm Flowchart Program

1. Start
2. Initialize F = 0,
C=0
3. Read F
4. C = (F-32) * 5/9
5. Write C
6. Stop

6|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
11. Draw a flowchart for computing factorial N, where N! = 1 * 2 * 3 * …… N
Algorithm Flowchart Program
i=i+1
Start
1. Start
2. Read N
3. Initialize F =1, i Read N
=1
4. F = F * i;
5. Increment i by 1 F=1
6. Repeat step 4 & i=1

5 until i = N
7. Print F
F=F*i
8. Stop

Is
i = N?

Yes

Write F

Stop

No
7|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
12. Find the Sum of First Five Natural Numbers Algorithm
Flowchart Program

1. Start
2. Initialize count = 0, sum
=0
3. count = count + 1
4. sum = sum + count
5. Repeat steps 3,4 until
count > 5
6. Print sum
7. Stop

13. Calculating sum of integers 1 to 100


Algorithm Flowchart Program 1. Start

2. Initialize count i = 1, sum


= 0 3. sum = sum + i Yes
4. Increment i by 1
Write
5. Repeat steps 3 & 4 until i sum
> 100 6. Print sum
7. Stop
Start

i=1
sum = 0

sum = sum + ii

=i+1

Stop

No
Is i>100?

8|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
14. To find the sum of n natural Numbers Algorithm
Flowchart Program

1. Start
2. Read n
3. count=0
4. sum=0
5. count = count + 1
6. sum = sum + count
7. Repeat steps 5 & 6
until
count > n
8. Print sum
9. Stop
9|PageYoutube.com/EngineersTutorwww.EngineersTutor.com
15. Sum of squares of n natural numbers Algorithm
Flowchart Program

8. Stop
1. Start
2. Read n
3. i = 0, sum = 0
4. i = i + 1
5. sum = sum + (i*i)
6. Repeat steps 4 and 5
until i > n 7. Print sum
Is
i>n

Yes
Write
sum

Stop

No
Start

Read n

i=0
sum = 0

i=i+1
sum = sum + (i*i)

10 | P a g e Y o u t u b e . c o m / E n g i n e e r s T u t o r w w w . E n g i n e e r s T u t o r . c o m
16. To find the sum of all even numbers up to ‘n’ Algorithm
Flowchart Program

1. Start
READ n
2. Read n
3. count=0
4. sum=0
count = 0
5. count = count + 2 sum = 0
6. sum = sum + count
7. Repeat steps 5 & 6 until
count ≤ n 8. Print sum count = count+ 2 sum = sum +
9. Stop

count

Is
count ≤ n

Yes
Write
sum

Stop

No
Start
11 | P a g e Y o u t u b e . c o m / E n g i n e e r s T u t o r w w w . E n g i n e e r s T u t o r . c o m
17. To find Product of numbers up to N
Algorithm Flowchart Program
count ≤ n
1. Start No
2. Read n
Yes
3. count i = 1
Write
4. product = 1 product
5. product=count*product 6.
count = count + 1
7. Repeat steps 5,6 until Stop
count ≤ N 8. Print product
9. Stop
Start

READ n

count i = 1
product = 1

count = count + 1
product =
product*count

Is
12 | P a g e Y o u t u b e . c o m / E n g i n e e r s T u t o r w w w . E n g i n e e r s T u t o r . c o m
18. Sum of first 50 odd numbers
Algorithm Flowchart Program

1. Start
2. sum=0, n = 1
3. sum=sum + n
4. n = n + 2
5. Repeat steps 4 and 5
until
n ≤ 99
6. Print sum
7. Stop
13 | P a g e Y o u t u b e . c o m / E n g i n e e r s T u t o r w w w . E n g i n e e r s T u t o r . c o m

You might also like