Professional Documents
Culture Documents
Data Structures and Algorithms: Write An Algorithm To Check Whether A Number Is A Prime Number or Not
Data Structures and Algorithms: Write An Algorithm To Check Whether A Number Is A Prime Number or Not
Data Structures and Algorithms: Write An Algorithm To Check Whether A Number Is A Prime Number or Not
Exercise 1
Write an algorithm to check whether a number is a prime
number or not.
Ver. 1.0
Session 2
b. i = i + 1
Ver. 1.0
Session 2
Ver. 1.0
Session 2
Ver. 1.0
Session 2
Ver. 1.0
1
2
3
4
1
2
3
1
2
Session 2
Ver. 1.0
1
2
1
2
3
1
2
3
4
1
2
3
4
5
1
2
3
4
1
2
3
1
2
Session 2
Ver. 1.0
Set j = 0
Insert a space
Set j = j + 1
If j < n i, go to step b
// To display n i spaces
Set j = 1
Display the value of j and insert a space
Set j = j + 1
If j < i, then go to step f
// To display numbers from 1 to i
Set j = i 1
Session 2
Ver. 1.0
Session 2
Ver. 1.0
Session 2
Session 2
Ver. 1.0
Set k = 0
If str[j] = substr[k], go to step j, else go to step m
Set j = j + 1
Set k = k + 1
If j < len1 and k < len2, go to step i
If k = len2, go to step n, else go to step p
Display Substring found at position + (i + 1) + in the string
Exit
Set i = i + 1
Session 2
Ver. 1.0
Session 2
Session 2
end
7. Repeat until i equals 10: // If there are any elements left
// in A1, copy them to
result
// array
a. result [k] = A1 [i]
b. Set k = k + 1
c. Set i = i + 1
Ver. 1.0
Session 2
Ver. 1.0
Session 2
Ver. 1.0
Session 2
Ver. 1.0
Session 2
Ver. 1.0
Session 2
Session 2
Ver. 1.0
If j < 3, go to step 6.
Set i = i + 1.
If i < 3, go to step 5.
Display result.
Session 2
Ver. 1.0
Session 2
Ver. 1.0
2))
Session 2