Practice Questions
-
1. Write a program to find the square and cube of a given number.
-
2. Write a program to check if a given year is a leap year or not.
-
3. Write a program to calculate the sum of the first 100 natural numbers.
-
4. Write a program to check if a given number is even or odd.
-
5. Write a program to print the sum of all even numbers from 1 to any given number.
-
6. Write a program to print the sum of all odd numbers from 1 to any given number.
-
7. Write a program to count the number of digits in a given number.
-
8. Write a program to calculate the sum of the digits of a given number.
-
9. Write a program to print the multiplication table of a given number.
-
10. Write a program to reverse a given number. For example, if the input is 12345, the output should be 54321.
-
11. Write a program that prints the numbers from 1 to 100. But for multiples of three, print 'Fizz' instead of the number, and for multiples of five, print 'Buzz.' For numbers that are multiples of both three and five, print 'FizzBuzz.'
-
12. Write a program to calculate the power of a number without using the Math.pow() function.
-
13. Write a program to check if a given number is prime or not.
-
14. Write a program to find and print all the prime numbers within 1-100.
-
15. Write a program to calculate the factorial of a given number.
-
16. Write a program to print the Fibonacci series up to a given number.
-
17. Write a program to calculate the sum of the first 20 Fibonacci numbers.
-
18. Write a program to check if a given number is a perfect number.
-
19. Write a program to check if a given number is an Armstrong number.
-
20. Write a program to check if a given number is a strong number.
-
21. Write a program to check a number whose last digit is 7.
-
22. Print the number which ends with 7 or is divided by 7.
-
23. Print numbers up to 500 that are divided by 7 and end with 7.
-
24. Write a program to print the factors of a number and also print the number of factors of that number.