Campusmonk DSA BlackBook Series – Part 1 (Exam Pattern)

Q1. Count All Digits of a Number

Problem Statement:
Given an integer n, write a program to count the total number of digits in n.

Input Format:

Output Format:

Examples:

Input: 4

Output: 1

 

Input: 14

Output: 2

 

📎 Practice Link (GFG)


 

✅ Q2. Count Number of Odd Digits

Problem Statement:
Given an integer n, return the number of odd digits present in n.

Input Format:

Output Format:

Examples:

Input: 5

Output: 1

 

Input: 25

Output: 1

 


 

✅ Q3. Reverse a Number

Problem Statement:
Given an integer n, return the number formed by reversing its digits.
Ignore any leading zeros in the reversed number.

Input Format:

Output Format:

Examples:

Input: 1234

Output: 4321

 

Input: 120

Output: 21

 

📎 Practice Link (LeetCode)


 

✅ Q4. Check if a Number is Palindrome

Problem Statement:
Write a program to check whether a given number n is a palindrome.
A number is a palindrome if it reads the same forwards and backwards.

Input Format:

Output Format:

Examples:

Input: 121

Output: true

 

Input: 123

Output: false

 

📎 Practice Link (LeetCode)


 

✅ Q5. Find the Largest Digit in a Number

Problem Statement:
Given a positive integer n, write a program to find the largest digit in the number.

Input Format:

Output Format:

Examples:

Input: 5492

Output: 9

 

Input: 103

Output: 3

 


 

✅ Q6. Print All Divisors of a Number

Problem Statement:
Given a number n, write a program to print all the divisors of n in ascending order.

Input Format:

Output Format:

Examples:

Input: 12

Output: 1 2 3 4 6 12

 

Input: 7

Output: 1 7

 

📎 Practice Link (GFG)


 

✅ Q7. Factorial of a Number

Problem Statement:
Write a program to find the factorial of a given number n.

Input Format:

Output Format:

Examples:

Input: 5

Output: 120

 

Input: 1

Output: 1

 

📎 Practice Link (HackerEarth)


 

✅ Q8. Check if a Number is Armstrong

Problem Statement:
A number is called an Armstrong number if the sum of its digits raised to the power of the number of digits is equal to the number itself.
Write a program to check if the given number is Armstrong.

Input Format:

Output Format:

Examples:

Input: 153

Output: true

 

Input: 123

Output: false

 

📎 Practice Link (GFG)


 

✅ Q9. Check for Perfect Number

Problem Statement:
A number is said to be perfect if it is equal to the sum of its proper divisors (excluding itself).
Write a program to check whether a number is perfect.

Input Format:

Output Format:

Examples:

Input: 28

Output: true

Explanation: 1 + 2 + 4 + 7 + 14 = 28

 

Input: 15

Output: false

 

📎 Practice Link (LeetCode)


 

✅ Q10. Check if a Number is Prime

Problem Statement:
Write a program to check whether the given number n is a prime number or not.

Input Format:

Output Format:

Examples:

Input: 7

Output: true

 

Input: 9

Output: false

 

📎 Practice Link (GFG)