Find the number of digits.
Take a number from the user and print the count of digits in that number.
Note:
Complete the Find_Digits
function. No need to take any input.
Find_Digits
function. No need to take any input.
const Find_Digits = (N) =>
{
var count = 0;
while(N >= 1){
N = (N/10);
count++;
}
return (count);
};
Find the Fives.
Among all the digits from 0−9, PrepBuddy likes number 5. He has a number and wants you to find out the number of times 5 occurred in the given number.
Note: Complete the Find_Five
function. No need to take any input.
Find_Five
function. No need to take any input.
const Find_Five = (N) =>
{
var count = 0;
var M = 0;
while(M >= 1){
M = N%10;
if (M === 5){
count++;
return count;
}
}
};
Find Sum.
You are given an integer N
, and your task is to find the sum of all the even integers starting from 1 upto N(Ninclusive)
.
Note: Complete the findSum
function. No need to take any input.
N
, and your task is to find the sum of all the even integers starting from 1 upto N(Ninclusive)
.findSum
function. No need to take any input.const findSum = (n) => {
var j = 0;
for(var i=0; i <= n; i++ ){
if(i%2 === 0){
j = j+i;
}
}
return j;
};
Find the sum of the digits of a given number.
Write a program that takes a number from the user and get the sum of the digits present in the number.
Note: Complete the Number_Sum
function. No need to take any input.
Number_Sum
function. No need to take any input.const Number_Sum = (N) => {
var O = 0;
while(N >= 1){
var M = N%10;
O = M+O;
N = parseInt(N/10);
}
return O;
};
Print the Odds.
Write a program which takes a number from user and print all odd numbers in between 2 and N
, but print 2 first.
Note: Complete the Print_Odd
function. No need to take any input.
N
, but print 2 first.Print_Odd
function. No need to take any input.const Print_Odd = (N) =>{
for( var i=2 ; i <= N ; i++){
if(i === 2){
console.log(i);
}
else{
if(i%2 === 1){
console.log(i);
}
}
}
};
Print the Pattern.
Write a program which ask user for no of lines and print a pattern using an asterik.
Note: Complete the Print_pattern
function. No need to take any input.
Print_pattern
function. No need to take any input.const Print_pattern = (N) => {
for( var i = 1; i < N; i++){
var s = "";
for( var j = 1; j < i; j++){
s = s+"*";
}
console.log(s);
}
};
Check whether a Number is a prime or not.
Write a program which takes a number from user and check whether number is prime number or not a prime number.
Note: Complete the Prime_Check
function. No need to take any input.
Prime_Check
function. No need to take any input.const Prime_Check = (N) => {
if(N === 1){
return "NO"
}
else{
for(var i = 2; i < N ; i++){
if( N%i === 0){
return "NO";
}
}
return "YES";
}
};
Print Numbers.
You are given an integer N
, and your task is to print all the integers starting from 1 upto N(Ninclusive)
.
Note: Complete the printNumbers
function. No need to take any input.
N
, and your task is to print all the integers starting from 1 upto N(Ninclusive)
.printNumbers
function. No need to take any input.const printNumbers = (n) => {
for(let i = 1;i <= n;i++){
console.log(i)
}
};
Print the Table.
Write a program which takes a number from user and print the table.
Note: Complete the Triangle_Check
function. No need to take any input.
Triangle_Check
function. No need to take any input.const Print_Table = (N) => {
for(var i = 1; i <= 10; i++){
console.log(`${N} * ${i} = `,N*i)
}
};