0% found this document useful (0 votes)
36 views

Examples of Algorithms and Flowcharts (With C Code) : Finding Area of The Square

The document provides 17 examples of algorithms, flowcharts, and C code to solve common mathematical and logical problems. For each problem, it lists the steps of the algorithm, draws the corresponding flowchart, and provides brief C code to implement the solution. The examples cover topics like calculating sums, averages, areas, greatest of numbers, factorials, and products.

Uploaded by

Zero
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)
36 views

Examples of Algorithms and Flowcharts (With C Code) : Finding Area of The Square

The document provides 17 examples of algorithms, flowcharts, and C code to solve common mathematical and logical problems. For each problem, it lists the steps of the algorithm, draws the corresponding flowchart, and provides brief C code to implement the solution. The examples cover topics like calculating sums, averages, areas, greatest of numbers, factorials, and products.

Uploaded by

Zero
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/ 12

Examples of Algorithms and Flowcharts (with C code)

1. To find sum of two numbers


Algorithm Flowchart Program

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

c=a+b

Write c

Stop

2. Finding Area of the square


Algorithm Flowchart Program

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

Write
area

Stop

2|Page Youtube.com/ EngineersTutor www.EngineersTutor.com


3. Finding Area of the rectangle
Algorithm Flowchart Program

Start

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

area = a*b

Write
area

Stop

4. Area of a triangle where three sides are given


Algorithm Flowchart Program

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

Write
A

Stop

3|Page Youtube.com/ EngineersTutor www.EngineersTutor.com


5. Find the area & perimeter of a square
Algorithm Flowchart Program

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

Write
A, P

Stop

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|Page Youtube.com/ EngineersTutor www.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|Page Youtube.com/ EngineersTutor www.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 Read P, N, R
4. Print SI
5. Stop
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|Page Youtube.com/ EngineersTutor www.EngineersTutor.com


11. Draw a flowchart for computing factorial N, where N! = 1 * 2 * 3 * …… N
Algorithm Flowchart Program

Start
1. Start
2. Read N
3. Initialize F =1, i = 1
Read N
4. F = F * i;
5. Increment i by 1
6. Repeat step 4 & 5 until i = N
F=1
7. Print F i=1
8. Stop

F=F*i

i=i+1 No Is
i = N?

Yes

Write F

Stop

7|Page Youtube.com/ EngineersTutor www.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 Start
3. sum = sum + i
4. Increment i by 1
i=1
5. Repeat steps 3 & 4 until i > 100 sum = 0
6. Print sum
7. Stop
sum = sum + i

i=i+1

No Is
i>100?

Yes
Write
sum

Stop

8|Page Youtube.com/ EngineersTutor www.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|Page Youtube.com/ EngineersTutor www.EngineersTutor.com


15. Sum of squares of n natural numbers
Algorithm Flowchart Program

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

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

No Is
i>n

Yes
Write
sum

Stop

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 www.EngineersTutor.com
16. To find the sum of all even numbers up to ‘n’

Algorithm Flowchart Program

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

sum = sum + count

No Is
count ≤ n

Yes
Write
sum

Stop

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 www.EngineersTutor.com
17. To find Product of numbers up to N

Algorithm Flowchart Program

1. Start Start
2. Read n
3. count i = 1
4. product = 1 READ n
5. product=count*product
6. count = count + 1
7. Repeat steps 5,6 until count ≤ N count i = 1
8. Print product product = 1
9. Stop

count = count + 1
product = product*count

Is
count ≤ n

No

Yes
Write
product

Stop

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 www.EngineersTutor.com
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 www.EngineersTutor.com

You might also like