V.Vidhya Logo

V.Vidhya

Loops Cumulative


Q1.

Write a JS program to delete all occurrences of a given number in a given array.

arr: 1, 2, 3, 4, 5, 6, 2, 3

// input
num: 2

// output
arr: 1, 3, 4, 5, 6, 3

// Notice that all 2's (num) are removed from array

Q2.

Print the factorial of a given number n.

Factorial of a number n is the product of all positive integers less than or equal to a given positive integer and denoted by that integer.

// ! is a sign of factorial 

5! = 120 

// (factorial of 5) = 5*4*3*2*1 = 120

// Note that 0! is always 1, not 0

Q3.

Find the largest number in a given array with only positive numbers.

numbers: 23, 59, 17, 61, 34, 46, 8

// output
largest number: 61

Q4. (Adv.)

Write a JS program to find the number of digits in a given number.

// case 1
// input
number: 287152

// output
count: 6

// case 2
// input
number: 397

// output
count: 3

Q5. (Adv.)

Write a JS program to find the sum of digits in a given number.

(NOTE: The number of digits of a given number can be anything.)

// case 1
// input
number: 287152;

// output
sum: 25
// sum of all digits of the given number 287152 (2 + 8 + 7 + 1 + 5 + 2)

// case 2
// input
number = 397;

// output
sum: 19
// (3 + 9 + 7)

Prev Post
Nested for (loop)
Next Post
Object Literals