Class XII Computer Science Practical Programs
(With Outputs)
1. Factorial using Recursion
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n-1)
num = int(input("Enter number: "))
print("Factorial:", factorial(num))
Output:
Enter number: 5
Factorial: 120
2. Fibonacci Series
def fib(n):
if n <= 1:
return n
return fib(n-1) + fib(n-2)
n = int(input("Enter terms: "))
for i in range(n):
print(fib(i), end=" ")
Output:
Enter terms: 6
0 1 1 2 3 5
3. Palindrome Check
def is_palindrome(s):
if len(s) <= 1:
return True
if s[0] != s[-1]:
return False
return is_palindrome(s[1:-1])
s = input("Enter string: ")
print("Palindrome" if is_palindrome(s) else "Not Palindrome")
Output:
Enter string: madam
Palindrome
SQL: Display All Records
SELECT * FROM student;
Output:
roll | name | class | marks
1 | Aman | 12 | 85
2 | Riya | 12 | 90
3 | Rahul | 12 | 78