Practice Top 30 C++ Programming Questions on Numbers
Q1. Write a program to check whether a given number is even or odd.
Input:
7
Expected Output:
7 is odd.
Q2. Write a program to calculate the sum of the digits of a given number.
Input:
123
Expected Output:
Sum of digits: 6
Q3. Write a program to reverse the digits of a given number.
Input:
456
Expected Output:
Reversed number: 654
Q4. Write a program to check if a given number is a prime number.
Input:
11
Expected Output:
11 is a prime number.
Q5. Write a program to calculate the factorial of a given number.
Input:
5
Expected Output:
Factorial: 120
Q6. Write a program to check if a given number is a perfect number.
Input:
6
Expected Output:
6 is a perfect number.
Q7. Write a program to find the GCD of two numbers.
Input:
24 36
Expected Output:
GCD: 12
Q8. Write a program to find the LCM of two numbers.
Input:
4 5
Expected Output:
LCM: 20
Q9. Write a program to check whether a given number is an Armstrong number.
Input:
153
Expected Output:
153 is an Armstrong number.
Q10. Write a program to check whether a given number is a palindrome.
Input:
121
Expected Output:
121 is a palindrome number.
Q11. Write a program to count the number of digits in a given number.
Input:
4567
Expected Output:
Number of digits: 4
Q12. Write a program to check if a number is an automorphic number.
Input:
76
Expected Output:
76 is an automorphic number.
Q13. Write a program to find the sum of the first N natural numbers.
Input:
10
Expected Output:
Sum: 55
Q14. Write a program to find the product of the digits of a given number.
Input:
234
Expected Output:
Product of digits: 24
Q15. Write a program to find the smallest digit in a given number.
Input:
8731
Expected Output:
Smallest digit: 1
Q16. Write a program to find the largest digit in a given number.
Input:
5289
Expected Output:
Largest digit: 9
Q17. Write a program to check if a number is a strong number.
Input:
145
Expected Output:
145 is a strong number.
Q18. Write a program to find all the prime factors of a given number.
Input:
28
Expected Output:
Prime factors: 2 2 7
Q19. Write a program to generate the first N numbers in the Fibonacci sequence.
Input:
7
Expected Output:
Fibonacci sequence: 0 1 1 2 3 5 8
Q20. Write a program to check if a number is a perfect square.
Input:
49
Expected Output:
49 is a perfect square.
Q21. Write a program to check if a number is a Harshad number.
Input:
18
Expected Output:
18 is a Harshad number.
Q22. Write a program to calculate the HCF of two numbers using the Euclidean algorithm.
Input:
60 48
Expected Output:
HCF: 12
Q23. Write a program to calculate the power of a number using a loop.
Input:
No input is required.
Expected Output:
Result: 32
Q24. Write a program to find the Nth prime number.
Input:
6
Expected Output:
6th prime number: 13
Q25. Write a program to print the multiplication table of a given number.
Input:
3
Expected Output:
3 x 1 = 3
3 x 2 = 6
...
3 x 10 = 30
Q26. Write a program to check if a number is a spy number.
Input:
123
Expected Output:
123 is a spy number.
Q27. Write a program to check if a number is a neon number.
Input:
9
Expected Output:
9 is a neon number.
Q28. Write a program to check if a number is a duck number.
Input:
102
Expected Output:
102 is a duck number.
Q29. Write a program to find the sum of the squares of the digits of a number.
Input:
34
Expected Output:
Sum of squares: 25
Q30. Write a program to check if a number is a binary number (contains only 0 and 1).
Input:
101010
Expected Output:
101010 is a binary number.
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!