Bertrand's Postulate in C++

sudhir sharma
Updated on 17-Jul-2020 12:00:29

194 Views

Bertrand’s postulates is a mathematical showroom which states that for every number n>3, there exists a prime number p which lies between n and 2n-2.The formula for Bertrand's Postulaten < p < 2n -2Where n is a number such that n>3 and p is a prime number.Prime number − A number is a prime number if it's only factors are 1 and itself.A less restrictive formulation of Bertrand’s postulate isn < p < 2n , for all n>1.ExamplesNumber5Output7Explanationprime number in range 5 and 2*5 i.e. prime number between 5 and 10Number11Output13, 17, 19Explanationprime number in range 11 and 2*11 i.e. ... Read More

Berkeley's Algorithm in C/C++

sudhir sharma
Updated on 17-Jul-2020 11:56:44

2K+ Views

Berkeley’s Algorithm is an algorithm that is used for clock Synchronisation in distributed systems. This algorithm is used in cases when some or all systems of the distributed network have one of these issues −A. The machine does not have an accurate time source.B. The network or machine does not have a UTC server.Distributed system contains multiple nodes that are physically separated but are linked together using a network.Berkeley’s AlgorithmIn this algorithm, the system chooses a node as master/ leader node. This is done from pool nodes in the server.The algorithm is −An election process chooses the master node in ... Read More

Combine Multiple Images into a Single One Using JavaScript

AmitDiwan
Updated on 17-Jul-2020 11:55:27

7K+ Views

Following is the code for combining multiple images into a single one using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Combining multiple images into a single one CLICK HERE Click on the above button to combine the two images above together    let imgEle1 = document.querySelectorAll(".image")[0];    let imgEle2 = document.querySelectorAll(".image")[1];    let resEle = document.querySelector(".result");    var context = resEle.getContext("2d");    let BtnEle = document.querySelector(".Btn");    BtnEle.addEventListener("click", () => {    resEle.width = imgEle1.width;       resEle.height = imgEle1.height;       context.globalAlpha = 1.0;       context.drawImage(imgEle1, 0, 0);       context.globalAlpha = 0.5;       context.drawImage(imgEle2, 0, 0);    }); OutputOn clicking the ‘CLICK HERE’ button −

Bayes Theorem for Conditional Probability in C/C++

sudhir sharma
Updated on 17-Jul-2020 11:54:29

880 Views

Conditional probability denoted by P(A|B) is the probability of occurrence of an event ‘A’ given that event ‘B’ has already occurred.Formula for conditional probability −P(A|B) = P( A⋂B ) / P(B)Bayes’s TheoremIt is the formula that shows the relation between probabilities of occurrences of mutually dependent events i.e. it given the relation between their conditional probabilities.Given an event A and another event B, according to bayes’ theorem, P(A/B) = {P(B/A) * P(A)} / P(B)Lets derive the formula for Bayes’ theorem, For this we will use the formula for conditional probability, P(A|B) = P( A?B ) / P(B) —— 1 P(B|A) ... Read More

Sort Strings with Accented Characters Using JavaScript

AmitDiwan
Updated on 17-Jul-2020 11:52:50

412 Views

Following is the code to sort strings with accented characters in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color:blueviolet    }    .sample{       color:red;    } Sort strings with accented characters [qué, cómo, dóndé, quién, cuánto, cuántos] CLICK HERE Click on the above button to sort the above array    let resEle = document.querySelector('.result');   ... Read More

TypeError: Undefined is Not an Object in JavaScript

AmitDiwan
Updated on 17-Jul-2020 11:50:46

2K+ Views

The “TypeError: ‘undefined’ is not an object” error occurs when a property is accessed or a method is called on an undefined object. This error is shown only on safari browser.Following is the code for TypeError − ‘undefined’ is not an object error in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color:blueviolet    } TypeError: ‘undefined’ is not an object example CLICK ... Read More

Basics of File Handling in C Programming

sudhir sharma
Updated on 17-Jul-2020 11:48:45

21K+ Views

File Handling is the storing of data in a file using a program. In C programming language, the programs store results, and other data of the program to a file using file handling in C. Also, we can extract/fetch data from a file to work with it in the program.The operations that you can perform on a File in C are −Creating a new fileOpening an existing fileReading data from an existing fileWriting data to a fileMoving data to a specific location on the fileClosing the fileCreating or opening file using fopen()The fopen() function is used to create a new ... Read More

Convert NodeList to Array in JavaScript

AmitDiwan
Updated on 17-Jul-2020 11:47:29

355 Views

Following is the code to convert a node list to an array in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       display: inline-block;       font-size: 20px;       font-weight: 500;       color: white;       background-color: blue;       padding:10px;       width: 100px;       height: 100px;    } Convert a node list to an array 1 2 3 4 CLICK HERE Click on the above button to change colors of all the above div    let sampEle = document.querySelectorAll('.sample');    let BtnEle = document.querySelector('.Btn');    BtnEle.addEventListener('click',()=>{       Array.from(sampEle).forEach(item=>{          item.style.backgroundColor = 'red';       })    }) OutputOn clicking the ‘CLICK HERE’ button −

Check If a Property Exists in an Object with JavaScript

AmitDiwan
Updated on 17-Jul-2020 11:46:18

116 Views

Following is the code to check if a property is in an object in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } Checking a property in an object CLICK HERE Click on the above button to check if firstName property is present in obj object    let resEle = document.querySelector(".result");    let obj = { firstName: "Rohan", lastName: "Sharma", ... Read More

Pseudo Mandatory Parameters in JavaScript

AmitDiwan
Updated on 17-Jul-2020 11:43:22

153 Views

Following is the code to implement pseudo mandatory parameters in functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } Optional function parameters CLICK HERE Click on the above button to call the add() and multiply() function    let resEle = document.querySelector(".result");    function add(a = 0, b = 0) {       return a + b;    }    function multiply(a, b) {       a = a || 0;       b = b || 0;       return a + b;    }    document.querySelector(".Btn").addEventListener("click", () => {       resEle.innerHTML = "Sum of the numbers = " + add() + "";       resEle.innerHTML +=       "Multiplication of the numbers = " + multiply() + "";    }); OutputOn clicking the ‘CLICK HERE’ button −

Advertisements