Python Program
Python Program
##Reverse a number
num = int(input("Enter a number: "))
reversed_num = 0
while num > 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit
num //= 10
print(f"Reversed number: {reversed_num}")
###Pattern Printing
###Array-Based Problems
##Reverse a string
string = input("Enter a string: ")
reversed_string = ""
for char in string:
reversed_string = char + reversed_string
print(f"Reversed string: {reversed_string}")
###Number Manipulation
if num == sum_of_powers:
print(f"{num} is an Armstrong number.")
else:
print(f"{num} is not an Armstrong number.")
###Matrix Manipulation
matrix = []
print("Enter the matrix elements row by row:")
for i in range(rows):
row = list(map(int, input().split()))
matrix.append(row)
is_symmetric = True
for i in range(rows):
for j in range(rows):
if matrix[i][j] != matrix[j][i]:
is_symmetric = False
break
if is_symmetric:
print("The matrix is symmetric.")
else:
print("The matrix is not symmetric.")
is_identity = True
for i in range(n):
for j in range(n):
if i == j and matrix[i][j] != 1:
is_identity = False
break
elif i != j and matrix[i][j] != 0:
is_identity = False
break
if is_identity:
print("The matrix is an identity matrix.")
else:
print("The matrix is not an identity matrix.")
if cols1 != rows2:
print("Matrix multiplication is not possible.")
else:
result = [[0 for _ in range(cols2)] for _ in range(rows1)]
for i in range(rows1):
for j in range(cols2):
for k in range(cols1):
result[i][j] += matrix1[i][k] * matrix2[k][j]
print("Result of matrix multiplication:")
for row in result:
print(*row)
###Logical and Miscellaneous Problems
if divisors_sum == n:
print(f"{n} is a perfect number.")
else:
print(f"{n} is not a perfect number.")
for _ in range(exponent):
result *= base
for i in range(len(arr)):
current_sum = 0
for j in range(i, len(arr)):
current_sum += arr[j]
if current_sum == target_sum:
count += 1
print("All subsets:")
for subset in subsets:
print(subset)
###Algorithmic Challenges