# Algorithm Example | Prime Number Algorithm

In this article Algorithm example we give the different examples of algorithm such as Prime number algorithm, Area of circle algorithm, Factorial algorithm etc.

#### Algorithm Example:

Q1. Write an algorithm to display addition of two numbers.

Step 1: Start

Step 2: Declare variables num1, num2 and sum.

Step 3: Read values num1 and num2.

Step 4: Add num1 and num2 and assign the result to sum.

Step 5: Display sum

Step 6: Stop

Algorithm Example:

Algorithm 1: Find the area of rectangle

Step 1: Start

Step 2: Declare variables l, b and area.

Step 3: Read values l and b.

Step 4:  Product l and b and assign the result to area.

area<- l * b

Step 5: Display area.

Step 6: Stop.

Algorithm 2: Find the area of circle

Step 1: Start

Step 2: Declare variables r and area.

Step 4:  Calculate r into r into 3.142 and assign the result to area.

area<- r * r * 3.142

Step 5: Display area.

Step 6: Stop.

Algorithm 3: Find the Volume of Cube

Step 1: Start

Step 2: Declare variables s and volume.

Step 4:  Calculate s into s into s and assign the result to volume.

volume<- s * s * s

Step 5: Display volume.

Step 6: Stop.

Algorithm 4: Write an algorithm to swap two numbers using the third variable

Step 1: Start

Step 2: Declare variables a, b and t.

Step 3: Read value a and b.

Step 4: Display values a and b (Before Swap)

Step 5: t = a

Step 6: a = b

Step 7: b = t

Step 8: Display values a and b (After Swap)

Step 9: Stop.

#### Algorithm 5:

Calculate simple interest.

Step 1: Start

Step 2: Declare variables p, r, y and SI.

Step 3: Read value p, r and y.

Step 4: Calculate p into r into y divided by 100 and assign the result into SI

Step 5: Display SI

Step 6: Stop.

Algorithm 6: Find the largest number among two numbers

Step 1: Start

Step 2: Declare variables a and b.

Step 3: Read values a and b.

Step 4: If a > b

Display a is the largest number and goto step 5.

Else If b > a Display b is the largest number.

Else Display both are equal numbers.

Step 5: Stop

Algorithm 7: Find the largest number among three numbers

Step 1: Start

Step 2: Declare variables a, b and c.

Step 3: Read values a, b and c.

Step 4: If a > b ,  If a > c

Display a is the largest number.

Else If b > c Display b is the largest number.

Else Display c is the greatest number.

Step 5: Stop

Algorithm 8: What is the algorithm for even or odd number?

Step 1: Start

Step 2: Declare variables a.

Step 4: If a % 2 = 0 then

Display a is the even number.

Else Display a is the odd number.

Step 5: Stop

#### Algorithm 9:

To display factorial of given number

Step 1: Start

Step 2: Declare variables a and fact.

Step 3: Initialize value fact=1

Step 4: If a greater than 0 then    a=4 , 3   ,  2   , 1  , 0

assign fact= fact into a       fact=4   , 12 ,  24  ,  24

Step 5: assign a= a-1 and goto step 4     a= 3   , 2   , 1  , 0

Step 6: display value of fact

Step 7: Stop

#### Some More:

POP- Introduction to Programming Using ‘C’

DS – Data structure Using C

OOP – Object Oriented Programming

Java Programming

DBMS – Database Management System

RDBMS – Relational Database Management System