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

Class12_CS_Important_Programs

Uploaded by

Sibling War
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)
10 views

Class12_CS_Important_Programs

Uploaded by

Sibling War
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/ 3

Class 12 CBSE Computer Science: Important Programs

Index
1. Calculate Factorial (Recursion)

2. Palindrome Checker

3. Binary Search (Recursive)

4. Insertion Sort

5. Fibonacci Sequence (Recursion)

6. File Handling (Read and Write)

7. Count Vowels in a String

8. Simple Interest Calculator

9. Armstrong Number Checker

10. Prime Number Checker

11. Merge Two Sorted Arrays

12. Matrix Addition

13. Find Largest Element in a List

14. Queue Implementation using List

15. Stack Implementation using List

1. Calculate Factorial (Recursion)


def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n-1)
print(factorial(5)) # Example

2. Palindrome Checker
def is_palindrome(s):
return s == s[::-1]
print(is_palindrome("radar")) # Example
3. Binary Search (Recursive)
def binary_search(arr, low, high, x):
if high >= low:
mid = (high + low) // 2
if arr[mid] == x:
return mid
elif arr[mid] > x:
return binary_search(arr, low, mid - 1, x)
else:
return binary_search(arr, mid + 1, high, x)
return -1
arr = [2, 3, 4, 10, 40]
x = 10
print(binary_search(arr, 0, len(arr)-1, x)) # Example

4. Insertion Sort
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j=i-1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key
arr = [12, 11, 13, 5, 6]
insertion_sort(arr)
print(arr) # Example

5. Fibonacci Sequence (Recursion)


def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
return fibonacci(n-1) + fibonacci(n-2)
for i in range(10):
print(fibonacci(i), end=" ") # Example

6. File Handling (Read and Write)


Code not yet provided for this program.

7. Count Vowels in a String


Code not yet provided for this program.
8. Simple Interest Calculator
Code not yet provided for this program.

9. Armstrong Number Checker


Code not yet provided for this program.

10. Prime Number Checker


Code not yet provided for this program.

11. Merge Two Sorted Arrays


Code not yet provided for this program.

12. Matrix Addition


Code not yet provided for this program.

13. Find Largest Element in a List


Code not yet provided for this program.

14. Queue Implementation using List


Code not yet provided for this program.

15. Stack Implementation using List


Code not yet provided for this program.

You might also like