Output based numerical javascript question answers solved
Here are some solved JavaScript questions with a focus on numerical operations. These questions cover basic arithmetic, looping, number manipulation, and more.
1. Find the sum of numbers from 1 to N.
Problem: Write a function to find the sum of numbers from 1 to N.
2. Check if a number is prime.
Problem: Write a function to check if a given number is prime.
3. Find the factorial of a number.
Problem: Write a function to find the factorial of a number.
4. Reverse a number.
Problem: Write a function to reverse a number.
5. Check if a number is Armstrong (Narcissistic) number.
Problem: Write a function to check if a number is an Armstrong number. An Armstrong number is a number that is equal to the sum of its digits each raised to the power of the number of digits.
For example, 153 is an Armstrong number because .
6. Find the greatest common divisor (GCD) of two numbers.
Problem: Write a function to find the GCD of two numbers using the Euclidean algorithm.
7. Find the Least Common Multiple (LCM) of two numbers.
Problem: Write a function to find the LCM of two numbers.
8. Fibonacci series up to Nth term.
Problem: Write a function to generate the Fibonacci series up to the Nth term.
9. Find the sum of digits of a number.
Problem: Write a function to find the sum of the digits of a number.
10. Find the power of a number (x^n).
Problem: Write a function to calculate the power of a number (x raised to the power n).
11. Find the largest digit in a number.
Problem: Write a function to find the largest digit in a given number.
12. Count the number of vowels in a string.
Problem: Write a function to count the number of vowels in a string.
13. Find if a number is a perfect number.
Problem: A perfect number is a positive integer that is equal to the sum of its proper divisors, excluding the number itself.
Example: 6 is a perfect number because 1 + 2 + 3 = 6.
14. Find the prime factors of a number.
Problem: Write a function to find all the prime factors of a given number.
15. Find the nth triangular number.
Problem: The nth triangular number is the sum of the first n natural numbers. Write a function to find the nth triangular number.
These problems provide a wide range of fundamental numerical challenges that help test a candidate's understanding of algorithms, number manipulation, loops, and arithmetic in JavaScript.
Comments
Post a Comment