Sum of Cubes of the First N Natural Numbers in PHP

AmitDiwan
Updated on 02-Jul-2020 07:06:10

559 Views

To find the sum of cubes of the first n natural numbers, the code is as follows −Example Live DemoOutputThe sum of cubes of first 8 natural numbers is 1296A function named ‘sum_of_cubes’ is defined that initializes a sum to 0. Every natural number is multiplied by itself thrice (cube) and added to the initial sum. The limit is the value that is passed as a parameter to the function. The limit is defined outside the function and the function is called. Relevant output is displayed on the console.

Sum of First N Natural Numbers Not Powers of a Specific Number in PHP

AmitDiwan
Updated on 02-Jul-2020 07:05:04

403 Views

To find the sum of the first n natural numbers who are not powers of a specific number ‘k’, the code is as follows −Example Live DemoOutputThe sum of fist 20 natural numbers that are not powers of 3 is 198A function named ‘sum_of_nums’ is defined and it calculates the sum of natural numbers that are not powers of a certain value. The number and the non-power number are passed as parameters to this function. Outside the function, a value each for n and k is defined and the function is called on these values. Relevant output is displayed on the ... Read More

Implement Rollover Effect for JButton in Java

raja
Updated on 02-Jul-2020 07:04:18

1K+ Views

A JButton is a subclass of AbstractButton and it can be used for adding platform-independent buttons to a GUI application. A JButon can generate an ActionListener interface when the button is pressed or clicked, it can also generate the MouseListener and KeyListener interfaces. We can implement the rollover effect when the mouse moves over a JButton by overriding the mouseEntered() method of the MouseListener interface.Syntaxvoid mouseEntered(MouseEvent e)Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class RollOverButtonTest extends JFrame {    private JButton button;    public RollOverButtonTest() {       setTitle("RollOverButton Test");       button = new JButton("Rollover Button");       button.addMouseListener(new MouseAdapter() {     ... Read More

Find Sum of 5th Powers of First N Natural Numbers in PHP

AmitDiwan
Updated on 02-Jul-2020 07:03:38

222 Views

To find the sum of the 5th powers of first n natural numbers, the code is as follows −Example Live DemoOutputThe sum of fifth powers of the first n natural numbers is 85648386825A function named ‘sum_of_fifth_pow’ is defined, and an initial sum value is defined as 0. The fifth power of every natural number up to a certain range is computed and added to the initial sum value. Outside the function, a value is defined and the function is called by passing this value as parameter. Relevant message is displayed on the console.

What is Byzantine Fault Tolerance

Prasanna Kotamraju
Updated on 02-Jul-2020 07:03:25

2K+ Views

Satoshi Nakamoto created Bitcoin in 2008, and he made the network very strong as a distributed, peer to peer model which is maintained without any intermediaries. Since then many digital currencies are created, which follow the same system where all nodes are sharing same information (same copy of Block chain) and any node can communicate with any other node safely across the network, knowing that they are displaying same data.Byzantine Fault Tolerance (BFT) is one of the most difficult challenges faced by the Block chain technology. All the participants of the cryptocurrency network need to agree, or give consensus regularly ... Read More

Find Average of First N Even Natural Numbers in PHP

AmitDiwan
Updated on 02-Jul-2020 07:02:20

849 Views

To find the average of the first n natural numbers that are even, the code is as follows −Example Live DemoOutputThe average of the first n natural numbers that are even is 12A function named ‘even_nums_avg’ is defined that adds up all the numbers up to a given limit, and divides it by total numbers of values. This is the average of the first few natural numbers. A value is defined, and the function is called by passing this value, which is actually the limit up to which the average of numbers needs to be found. Relevant message is displayed on ... Read More

Sum of Cubes of Odd Natural Numbers in PHP

AmitDiwan
Updated on 02-Jul-2020 07:01:25

306 Views

To find the sum of cubes of natural numbers that are odd, the code is as follows −Example Live DemoOutputThe sum of cubes of first 8 natural numbers that are even is 3968A function named ‘sum_of_cubes_even’ is defined that takes a limit on the natural number up to which the cube of every number needs to be found and each on them need to be added up. A ‘for’ loop is iterated over, and every number is cubed and added to an initial sum that was initially 0. The function is called by passing a number that is the limit as ... Read More

Check If All Digits of a Number Divide It in PHP

AmitDiwan
Updated on 02-Jul-2020 07:00:08

256 Views

To check if all digits of a number divide it in PHP, the code is as follows −Example Live Demo

Check if Total Number of Divisors is Even or Odd in PHP

AmitDiwan
Updated on 02-Jul-2020 06:58:31

243 Views

To check if the total number of divisors of a number is even or odd, the code is as follows −Example Live DemoOutputIt is an odd numberA function named ‘divisor_count’ is defined that gives the number of divisors of a given number that is passed as a parameter to the function. Now, each of these divisors is checked to see if it can be completely divided by 2, if yes, it is an even divisor, and otherwise, it is an odd divisor. Relevant message is displayed on the console.

Array Range Queries for Elements with Frequency Same as Value in C

Arnab Chakraborty
Updated on 02-Jul-2020 06:56:57

303 Views

Here we will see one interesting problem. We have one array with N elements. We have to perform one query Q as follows −The Q(start, end) indicates that number of times a number ‘p’ is occurred exactly ‘p’ number of times from start to end.So if the array is like: {1, 5, 2, 3, 1, 3, 5, 7, 3, 9, 8}, and queries are −Q(1, 8) − Here the 1 is present once, and 3 is present 3 times. So the answer is 2Q(0, 2) − Here the 1 is present once. So the answer is 1Algorithmquery(s, e) −Begin   ... Read More

Advertisements