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

Algorithms Collection

Uploaded by

Siddhant patil
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)
9 views

Algorithms Collection

Uploaded by

Siddhant patil
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/ 5

Algorithms Collection

1. Print Pyramids Pattern


Algorithm:
Start
1. Input the number of rows (n)
2. For i = 1 to n
3. For j = 1 to n-i
4. Print space
5. For k = 1 to 2*i-1
6. Print "*"
7. Print newline
Stop

2. Sum of Sine Series


Algorithm:
Start
1. Input number of terms (n)
2. Initialize sum = 0
3. Initialize x (angle in radians)
4. For i = 0 to n-1
5. term = ((-1)^i * x^(2i+1)) / factorial(2i+1)
6. sum = sum + term
7. Print sum
Stop

3. Matrix Operations
Algorithm:
Start
1. Declare 3x3 matrices A, B, and Result
2. Display menu:
a. Addition
b. Transpose
c. Multiplication
3. Input choice

4. If choice is Addition:
5. Input matrices A and B
6. For i = 0 to 2
7. For j = 0 to 2
8. Result[i][j] = A[i][j] + B[i][j]
9. Display Result

1
10. If choice is Transpose:
11. Input matrix A
12. For i = 0 to 2
13. For j = 0 to 2
14. Result[j][i] = A[i][j]
15. Display Result

16. If choice is Multiplication:


17. Input matrices A and B
18. For i = 0 to 2
19. For j = 0 to 2
20. Result[i][j] = 0
21. For k = 0 to 2
22. Result[i][j] += A[i][k] * B[k][j]
23. Display Result
Stop

4. String Operations
Algorithm:
Start
1. Input string str
2. Display menu:
a. Length
b. Reversal
c. Equality check
d. Palindrome check
3. Input choice

4. If choice is Length:
Without built-in:
5. Initialize count = 0
6. While str[count] != '\0'
7. Increment count
8. Print count

9. If choice is Reversal:
Without built-in:
10. Calculate length (len)
11. For i = 0 to len/2
12. temp = str[i]
13. str[i] = str[len-1-i]
14. str[len-1-i] = temp
15. Print reversed string

2
16. If choice is Equality:
Without built-in:
17. Input second string str2
18. Initialize flag = 1
19. For i = 0 until either string ends
20. If str[i] != str2[i]
21. flag = 0
22. break
23. Print result based on flag

24. If choice is Palindrome:


25. Create reversed string using reversal algorithm
26. Check equality with original string
27. Print result
Stop

5. Fibonacci Series using Recursion


Algorithm:
Start
1. Input number of terms (n)
2. For i = 0 to n-1
3. Call fibonacci(i) and print result

fibonacci(n):
4. If n <= 1
5. Return n
6. Else
7. Return fibonacci(n-1) + fibonacci(n-2)
Stop

6. Array Search using Function


Algorithm:
Start
1. Input array size (n)
2. Input array elements
3. Input search element (key)
4. Call searchElement(array, n, key)

searchElement(array, n, key):
5. For i = 0 to n-1
6. If array[i] equals key
7. Return i

3
8. Return -1

9. Print search result


Stop

7. Employee Management
Algorithm:
Start
1. Create Employee structure with fields:
- Name
- Designation
- Gender
- DOJ
- Salary

2. Input number of employees (n)


3. For i = 1 to n
4. Input employee details

5. Function countEmployees():
6. Return total number of employees

7. Function highSalaryEmployees():
8. For i = 0 to n-1
9. If employee[i].salary > 20000
10. Print employee details

11. Display results


Stop

8. Number Swapping
Algorithm for Pointer Swap:
Start
1. Input numbers a and b
2. Create pointers p1 = &a, p2 = &b
3. temp = *p1
4. *p1 = *p2
5. *p2 = temp
6. Print swapped numbers
Stop

4
Algorithm for Call by Reference:
Start
1. Input numbers a and b
2. Call swap(&a, &b)

swap(x, y):
3. temp = *x
4. *x = *y
5. *y = temp

6. Print swapped numbers


Stop

You might also like