Posts

Showing posts from August, 2023

Day 96: Current Date and Time of 100DaysCodingChallenge

Image
Hello all,  #day96  Day96  Today's  my task was to Write a Program to Display the Current Date and Time. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to display the date // get local machine date time const date = new Date(); const datetime = Date.now(); // get the date as a string const n = date.toDateString(); // get the time as a string //const time = datetime.toLocaleTimeString(); // display date console.log('Date: ' + n); // display time console.log('Time: ' + datetime); Output :         Happy Coding:) Day 96 Of 100 Days Coding Challenge Thank you...      

Day 95: Date and Time of 100DaysCodingChallenge

Image
Hello all,  #day95  Day95  Today's my task was to Write a Program to Display the Date and Time entered input required by the user. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to display the date and time // get date and time let y = parseInt(prompt("Enter Year : ")); let m = parseInt(prompt("Enter Month : ")); let d = parseInt(prompt("Enter Day : ")); let h = parseInt(prompt("Enter Hour : ")); let min = parseInt(prompt("Enter Minutes : ")); let s = parseInt(prompt("Enter Seconds : ")); //const date = new Date(2017, 2, 12, 9, 25, 30); const date = new Date(y, m, d, h, min, s); // get the date as a string const n = date.toDateString(); // get the time as a string const time = date.toLocaleTimeString(); // display date console.log('Date: ' + n); // display time console.log('Time: ' + time); Output :         Happy Coding:) Day 95 Of 100 Days Cod

Day 94: Spell Each Digit Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day94  Day94  Today's my task was to Write a Program to Spell each Digit Separately an input Number n and then have to spell each digit separately. (n is entered by user) using Recursion. Today's my task was to Write a Program to Spell each Digit Separately an input Number n and then have to spell each digit separately. (n is entered by user) using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  function spell_num(number) { if (number < 10) // base case. { console.log(number, ""); } else { spell_num(Math.floor(number / 10)); // recursive call. console.log(number % 10, ""); } } //spell_num(567); let n = parseInt(prompt("Enter a Number : ")); spell_num(n); const reduce = (fn, acc, [cur, rest]) => cur === undefined ? acc : reduce(fn, fn(acc, cur), rest); //console.log(reduce((a, b) => a + b, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9])); // 45 Output :         Happ

Day 93: Fibonacci Series Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day93  Day93  Today's my task was to Write a Program to Display Fibonacci Series only last Output Number a Certain Number n (n is entered by user) using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  const fibonacci = (n) => (n <= 2 ? 1 : fibonacci(n - 1) + fibonacci(n - 2)); //console.log(fibonacci(10)); // 55 let a = parseInt(prompt("Enter a Number : ")); console.log(fibonacci(a)); Output :         Happy Coding:) Day 93 Of 100 Days Coding Challenge Thank you...      

Day 92: LCM Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day92  Day92  Today's  my task was to Write a Program to Find LCM of two numbers entered by user using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // Javascript program to find LCM of two numbers // Recursive function to return gcd of a and b function gcd(a, b) { if (b == 0) return a; return gcd(b, a % b); } // Function to return LCM of two numbers function lcm(a, b) { return (a / gcd(a, b)) * b; } // Driver program to test above function // let a = 15, b = 20; let a = prompt("Enter a Number a : "); let b = prompt("Enter a Number b : "); console.log("LCM of " + a + " and " + b + " is " + lcm(a, b)); // This code is Output :         Happy Coding:) Day 92 Of 100 Days Coding Challenge Thank you...      

Day 91: GCD Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day91  Day91  Today's my task was to Write a Program to Find GCD of two numbers entered by user using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let a = prompt("Enter a : "); let b = prompt("Enter b : "); var gcd = function(a, b) { if (!b) { return a; } return gcd(b, a % b); }; //console.log(gcd(2154, 458)); console.log(gcd(a, b)); Output :         Happy Coding:) Day 91 Of 100 Days Coding Challenge Thank you...      

Day 90: Count Up Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day90  Day90  Today's task was to write a program that will give a countdown of numbers in ascending order upto to the number 10. lower number input entered by the user. Example: from 1 up to 10. Sample Input: 1 Sample Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 here, I have taken another input number randomly from the range of between 1 to 10 by myself. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let a = prompt("Enter a Number : "); // program to count down numbers to 1 function countUp(number) { // display the number console.log(number); // decrease the number value //const newNumber = number + 1; // base case if (number < 10) { //countDown(newNumber); return countUp(number + 1); } return 0; } //countDown(4); countUp(parseInt(a)); Output :         Happy Coding:) Day 90 Of 100 Days Coding Challenge Thank you...      

Day 89: Factorial Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day89  Day89  Today's my task was to Write a Program to Find Factorial of a given number N using Recursion. (N is entered by the user). I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  //let a = prompt("Enter a Number : "); // program to find the factorial of a number function factorial(x) { // if number is 0 if (x == 0) { return 1; } // if number is positive else { return x * factorial(x - 1); } } // take input from the user const num = prompt('Enter a positive Number: '); // calling factorial() if num is positive if (num >= 0) { const result = factorial(num); console.log(`The Factorial of ${num} is ${result}`); } else { console.log('Enter a positive Number.'); } function factorial1(n) { if (n >= 1) { return n * factorial(n - 1); } } //console.log(factorial(parseInt(a))); Output :         Happy Coding:) Day 89 Of 100 Days Coding Challenge Thank you...      

Day 88: Sum of Numbers Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day88  Day88  Today's task was to Write a Program to Find Sum of N Natural Numbers (entered by the user) using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to find the sum of natural numbers using recursion function sum(num) { if (num > 0) { return num + sum(num - 1); } else { return num; } } // take input from the user const number = parseInt(prompt('Enter a Positive Number : ')); const result = sum(number); // display the result console.log(`The Sum is ${result}`); Output :         Happy Coding:) Day 88 Of 100 Days Coding Challenge Thank you...      

Day 87: Exponential Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day87  Day87  Today's task was to write a program that gives the exponential of a given number entered by the user using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let n = prompt("Enter a Number : "); let p = prompt("Enter a Power : "); function exponential(num, power) { if (power == 1) { return num; } else { return num * exponential(num, power - 1); } } //exponential(3,4); console.log(exponential(n, p)); Output :         Happy Coding:) Day 87 Of 100 Days Coding Challenge Thank you...      

Day 86: String Reversal Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day86  Day86  Today's task was to write a program to reverse a string entered by the user using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let s = prompt("Enter a String : "); function StringRev(text) { if (text.length == 1) { return text; } else { return text.slice(-1) + StringRev(text.slice(0, -1)); } } //StringRev(“SessionStack”); console.log(StringRev(s)); Output :         Happy Coding:) Day 86 Of 100 Days Coding Challenge Thank you...      

Day 85: Decending Numbers Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day85  Day85  Today's task was to write a program that will give a countdown of numbers in descending order. higher number input entered by the user. Example: from 10 down to 1. Sample Input: 10 Sample Output: 10,9,8,7,6,5,4,3,2,1 I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let a = prompt("Enter a Number : "); function descendNum(StartNum) { console.log(StartNum); let NextNum = StartNum - 1; if (NextNum > 0) { descendNum(NextNum); } } //descendNum(10); descendNum(parseInt(a)); Output :         Happy Coding:) Day 85 Of 100 Days Coding Challenge Thank you...      

Day 84: Find Repeated Character From a String of 100DaysCodingChallenge

Image
Hello all,  #day84  Day84  Today's task was to Write a JavaScript program to find the Repeted Character in a given string. Words must be separated by only one space. Example: Sample Input: repeated Sample Output: e I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // character that is repeated function findRepeatFirstN2(s) { // This is O(N^2) method let p = -1, i, j; for (i = 0; i < s.length; i++) { for (j = i + 1; j < s.length; j++) { if (s[i] == s[j]) { p = i; break; } } if (p != -1) break; } return p; } // Driver code //let str = "geeksforgeeks"; let str = prompt("Enter a String : "); let pos = findRepeatFirstN2(str); if (pos == -1) console.log("Not found"); else console.log(str[pos]); // This code is contributed Output :         Happy Coding:) Day 84 Of 100 Days Coding Challenge Thank you...      

Day 83: Longest Word From a String of 100DaysCodingChallenge

Image
Hello all,  #day83  Day83  Today's task was to Write a JavaScript program to find the largest word in a given string. Words must be separated by only one space. Example: Sample Input: JavaScript code Sample Output: The Largest Word is JavaScript I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  function getLongestWord(str) { let words = str.split(' '); let maxLength = 0; let longestWord = ''; for (let i = 0; i < words.length; i++) { if (words[i].length > maxLength) { maxLength = words[i].length; longestWord = words[i]; } } //console.log(maxLength); console.log("The Longest Word is ", longestWord); } let str = prompt("Enter a String : "); getLongestWord(str); Output :         Happy Coding:) Day 83 Of 100 Days Coding Challenge Thank you...      

Day 82: Capital First Letter of a String of 100DaysCodingChallenge

Image
Hello all,  #day82  Day82  Today's task was to Write a program to capitalize the first letter of each word of a given string. Words must be separated by only one space Example: Sample Input: hardik kotak Sample Output: Hardik Kotak I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  function capital_letter(str) { str = str.split(" "); for (var i = 0, x = str.length; i < x; i++) { str[i] = str[i][0].toUpperCase() + str[i].substr(1); } return str.join(" "); } //console.log(capital_letter("Write a JavaScript program to capitalize the first letter of each word of a given string.")); let str = prompt("Enter a String : "); console.log(capital_letter(str)); Output :         Happy Coding:) Day 82 Of 100 Days Coding Challenge Thank you...      

Day 81: Word Count of a String of 100DaysCodingChallenge

Image
Hello all,  #day81  Day81  Today's task was to Write a program to count all the words in a given string. Words must be separated by only one space Example: Sample Input: hardik kotak Sample Output: number of words : 2 I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  //given input string. var OUT = 0; var IN = 1; // returns number of words in str function countWords( str) { var state = OUT; var wc = 0; // word count var i = 0; // Scan all characters one // by one while (i < str.length) { // If next character is a separator, // set the state as OUT if (str[i] == ' ' || str[i] == '\n'|| str[i] == '\t') state = OUT; // If next character is not a word // separator and state is OUT, then // set the state as IN and increment // word count

Day 80: Replace Characters of a String of 100DaysCodingChallenge

Image
Hello all,  #day80  Day80  Today's task was to Write a program to change every letter in a given string with the letter following it in the alphabet entered string by the user. (ie. a becomes b, p becomes q, z becomes a). Example: Sample Input: Abcdef Sample Output: Bcdefg I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  //function string_reverse(str) var newString = prompt("Enter a String : "); function LetterChanges(text) { //https://goo.gl/R8gn7u var s = text.split(''); for (var i = 0; i < s.length; i++) { // Caesar cipher switch (s[i]) { case ' ': break; case 'z': s[i] = 'a'; break; case 'Z': s[i] = 'A'; break; default: s[i] = String.fromCharCode(1 + s[i].charCodeAt(0)); } // Upper-case vowels switch (s[i]) { case 'a': case 'e': case 'i': case 

Day 79: Concatenation of a String of 100DaysCodingChallenge

Image
Hello all,  #day79  Day79  Today's task was to Write a Program to Concatenate (join) Two Strings entered by user. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let str1 = prompt("Enter a First String : "); let str2 = prompt("Enter a Second String : "); let str3 = str1.concat(str2); console.log(`The Contenation of two given strings \n${str1} and ${str2} is ${str3}`); Output :         Happy Coding:) Day 79 Of 100 Days Coding Challenge Thank you...      

Day 78: Length of a String of 100DaysCodingChallenge

Image
Hello all,  #day78  Day78  Today's task was to Write a Program to Find the Length of a String entered by the user. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  const str = prompt("Enter a String : "); console.log(`The Length of ${str} is ${str.length}`); Output :         Happy Coding:) Day 78 Of 100 Days Coding Challenge Thank you...      

Day 77: Remove Special Characters From String of 100DaysCodingChallenge

Image
Hello all,  #day77  Day77  Today's task was to Write a Program to Remove all Characters in a String Except Alphabets from a String using string input taken by the user. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // function to remove characters and // print new string function removeSpecialCharacter(s) { for (let i = 0; i < s.length; i++) { // Finding the character whose // ASCII value fall under this // range if (s[i] < 'A' || s[i] > 'Z' && s[i] < 'a' || s[i] > 'z') { // erase function to erase // the character s = s.substring(0, i) + s.substring(i + 1); i--; } } console.log(s); } // Driver code //let s = "$Gee*k;s..fo, r'Ge^eks?"; let s = prompt("Enter a String : "); re

Day 76: Number of Characters, Vowels, Digits, Special Characters of 100DaysCodingChallenge

Image
Hello all,  #day76  Day76  Today's my task was to Write a Program to Find the Number of Vowels, Consonants, Digits and Special Characters from a String using string input taken by the user. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // Program to count vowels, consonant, // digits and // special character in a given string. // Function to count number of vowels, consonant, // digitsand special character in a string. function countCharacterType(str) { // Declare the variable vowels, // consonant, digit // and special characters var vowels = 0, consonant = 0, specialChar = 0, digit = 0; // str.length() function to count number of // character in given string. for (var i = 0; i < str.length; i++) { var ch = str[i]; if ((ch >= "a" && ch <= "z") ||

Day 75: Frequency of Characters from String of 100DaysCodingChallenge

Image
Hello all,  #day75  Day75  Today's my task was to Write a Program to Find the Frequency of every Character from a String using string input taken by the user. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  function count( str , outp_map ) { for( let i = 0 ;i < str.length ;i++) { let k = outp_map.get(str[i]); outp_map.set(str[i], k+1) ; } //calling print function printans(outp_map); } //function create map to count character function count_occurs( test , callback ) { //checking string is valid or not if( test.length === 0 ) { console.log(" empty string "); return ; } else { // map for storing count values let ans = new Map(); for( let i = 0 ;i < test.length;i++) { ans.set(test[i], 0); } callback( test ,ans); } } // test string

Day 74: Sum of Prime Numbers of 100DaysCodingChallenge

Image
Hello all,  #day74  Day74  Today's my task was to Write a Program to check if an integer (entered by the user) can be expressed as the sum of two prime numbers,if yes then print all possible combinations with the use of functions. Example Enter a positive integer: 34 OUTPUT: 34 = 3 + 31 34 = 5 + 29 34 = 11 + 23 34 = 17 + 17 I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  //#include <stdio.h> let n = prompt("Enter a positive integer: "); //checkPrime(n); function isPrime(n){ let i, flag = 0; //scanf("%d", &n); for (i = 2; i <= n / 2; ++i) { // condition for i to be a prime number if (checkPrime(i) == 1) { // condition for n-i to be a prime number if (checkPrime(n - i) == 1) { console.log(`${n} = ${i} + ${n - i}`); flag = 1; } } } if (flag == 0) console.log(`${n} cannot be expressed as the sum of two prime numbers. `); return 0; } // functio

Day 73: Convert Binary to Decimal Number of 100DaysCodingChallenge

Image
Hello all,  #day73  Day73  Today's my task was to Write a Program to Convert Binary to Decimal number manually by creating user-defined functions. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // JavaScript program to convert binary to decimal // Function to convert binary to decimal function binaryToDecimal(n) { let num = n; let dec_value = 0; // Initializing base value to 1, i.e 2^0 let base = 1; let temp = num; while (temp) { let last_digit = temp % 10; temp = Math.floor(temp / 10); dec_value += last_digit * base; base = base * 2; } return dec_value; } // Driver program to test above function //let num = 10101001; let num = prompt("Enter a number : "); console.log("The Decimal Number is ", binaryToDecimal(num) + " "); // This code Output :         Happy Coding:) Day 73 Of 100 Days Coding Challenge Thank you...