0% found this document useful (0 votes)
3 views2 pages

How to Algorithm

The document outlines an algorithm for adding two numbers and printing the result, as well as a bubble sort algorithm for searching a value in an array. It includes steps for initializing variables, looping through the array, and conditionally printing values based on comparisons. Additionally, it describes a swap function for rearranging elements in the array during the sorting process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

How to Algorithm

The document outlines an algorithm for adding two numbers and printing the result, as well as a bubble sort algorithm for searching a value in an array. It includes steps for initializing variables, looping through the array, and conditionally printing values based on comparisons. Additionally, it describes a swap function for rearranging elements in the array during the sorting process.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Write an algorithm for a program that adds 2 number and prints the result.

Write and algorithm on bubble sort

Assume, we have an array ARR with length N. We want to search a value K in the array.

Step 1: Set J = 0
Step 2: Set I = 0
Step 3: J = J + 1
Step 4: Print “Found”
Step 5: If A<B then
Print A
Else if B<C then
Print B
Else
Print C
Step 6: Repeat steps 7 to 9 while I<N-1
Step 7: Print I
Step 8: I = I+1
Step 9: If I < 10 then
Print N
Step 10: Call SWAP(ARR[J], ARR[J+1])

Step 1: Set T = ARR[J]


Step 2: ARR[J] = ARR[J+1]
Step 3: ARR[J+1] = T

Step 11: Repeat steps 12 to 15 while I<N-1


Step 12: Repeat steps 13 to 14 While J<N-1
Step 13: Print J
Step 14: Print “A”
Step 15 Print “C”

Step 16: If A<B then


Print B
Step 17: Repeat steps 18 to 22 While I < N -1
Step 18: Print A

ARR[J] == K

1. You can assume some variables


2. Number each algorithm line
3. Use “Set” for first time use of variable in algorithm
4. Variables are capital letters only
5. 3 types Statements: general, if else, loop
6. Nested case

You might also like