Power in Mathematics in C++

sudhir sharma
Updated on 17-Apr-2020 06:55:32

166 Views

The power of a number is the times a number is multiplied to itself. Also knows as exponent or indices.a to the power b is b times a is multiplied by itself b times. 7 to the power 2 is 72 also known as 7 square is valued 49.Some common power values are −A number to the power 0 gives 1.A number to the power 1 gives the same number, as stated some multiplied once is the same.A number to the negative power is n times division. Example, a -3 = 1/a3 or (1/a)*(1/a)*(1/a)Now, let’s do some programming based on ... Read More

Power of a Prime Number r in n in C++

sudhir sharma
Updated on 17-Apr-2020 06:49:39

219 Views

In this problem, we are given two integer n and r. Our task is to find the power of the given prime number r in the factorial of the number n.Let’s take an example to understand the problemInput − n = 6 r = 2Output − 4Explanation −Factorial n, 6! = 6*5*4*3*2*1 = 720 720 = 24 * 32 * 5, power of 2 is 4To solve this problem, a simple solution would be directly finding the factorial and then finding the power of the prime number. But this is not the best solution.Another efficient solution is using a formula, ... Read More

Power Set in Lexicographic Order in C++

sudhir sharma
Updated on 17-Apr-2020 06:46:51

756 Views

In this problem, we are given string str. Our task is to print the power set of this string’s elements in lexicographical order.Power Set − The power set of a set is the set of all subsets of the set. Denoted by P(S) where s is the set.Example −S = {1, 2, 3} ; p(S) = {{}, {1}, {1, 2}, {1, 3}, {2}, {2, 3}, {3}, {1, 2, 3}}In this problem, we will treat the string as a set. So, its characters will be the elements of the set.Let’s take an example to understand the problemInput − str = “xyz”Output ... Read More

Powers of 2 to Required Sum in C++

sudhir sharma
Updated on 17-Apr-2020 06:43:33

672 Views

In this problem, we are given an integer N. Our task is to print the number which when raised to the power of 2 gives the number.Let’s take an example to understand the problemInput − 17Output − 0, 4Explanation − 17 = 24 + 20 = 16 + 1To solve this problem, we will divide the number with 2 recursively. By this method, every number can be represented as a power of 2. This method is used to convert the number to its binary equivalent.ExampleThe program to show the implementation of our solution Live Demo#include using namespace std; void sumPower(long ... Read More

Powers of Two and Subsequences in C++

sudhir sharma
Updated on 17-Apr-2020 06:41:39

206 Views

In this problem, we are given an array of N integers. Our task is to find the count of subsequences that can be formed such that if their elements are multiplied, they result in a number which is a power of two.Let’s take an example to understand the problem, Input − arr = [2, 5, 4]Output − 3Explanation − subsequences [2], [4] and [2, 4] give the desired result.To solve this problem, we need to understand the logic of power.Only those numbers with are powers of 2 will multiply to give the desired result. So, we have to consider only ... Read More

Rules for External Declarations in JShell in Java 9

raja
Updated on 16-Apr-2020 19:10:32

116 Views

JShell is a command-line tool introduced in Java 9, and it is Java's first official REPL tool to create a simple programming environment that reads the user's inputs, evaluates it, and prints the result.The declarations outside a class or interface (and declarations of classes and interfaces by themselves) have been created under the following rules.Rules for External Declarations:1) Access modifiers like public, protected, and private can be ignored. All declaration snippets can be accessible to all other snippets.jshell> private int i = 10; i ==> 10 jshell> System.out.println(i); 102) The modifier final can be ignored. Changes and inheritance are allowed.jshell> final class A {void m() {} } ... Read More

Create an Instance of VarHandle in Java 9

raja
Updated on 16-Apr-2020 14:11:28

216 Views

In general, a Variable Handle is simply typed reference to a variable. It will be an array element, an instance or static field of the class. VarHandle class can provide write and read access to variables under specific conditions. These are immutable and have no visible condition. In addition, they can't be sub-classified, and each VarHandle has a generic type T, which is the type of each variable represented by this VarHandle. The objective of VarHandle is to define a standard for calling equivalents of java.util.concurrent.atomic and sun.misc.Unsafe operations on fields and array elements.In the below example, we can use ... Read More

Implement Flow Publisher Interface in Java 9

raja
Updated on 16-Apr-2020 10:36:29

803 Views

A Publisher interface is a provider of an unbounded number of sequenced elements, publishing them according to the demand received from its Subscriber(s). In response to call Publisher.subscribe(Subscriber), the possible invocation sequences for methods on the Subscriber. It means that the onSubscribe() method, followed by the unbounded number of onNext() methods (as requested by Subscriber) followed by an onError() method, if there is a failure or an onComplete() method when no more elements available as long as Subscription is not canceled.Syntaxpublic interface Publisher {    public void subscribe(Subscriber

Create a JavaFX Slider

Maruthi Krishna
Updated on 16-Apr-2020 08:30:35

421 Views

JavaFX provides a class known as Slider, this represents a slider component that displays a continuous range of values. This contains a track on which the numerical values are displayed. Along the track, there is a thumb pointing to the numbers. You can provide the maximum, minimum and initial values of the slider. To create a slider you need to instantiate the Slider class, set the required properties and, add it to the scene.Exampleimport javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Slider; import javafx.scene.layout.VBox; import javafx.stage.Stage;         public class SliderExample extends Application {    public void start(Stage stage) ... Read More

Difference Between Fedora and CentOS

Mahesh Parahar
Updated on 16-Apr-2020 06:51:18

256 Views

FedoraFedora is Linux based and open-source operating system intended for developers and system administrators. It is supported by a huge Red Hat Community. It was introduced in Sep 2003. Initially, it was also known as Fedore Core. Fedora OS uses IPSec to connect to remote machines or networks. It uses Internet Key Exchange, IKE protocol to make secure, robust connections between machines.CentOSCentOS is also Linux based open-source distributed operating system. It is quite stable and robust. It was developed over source code Red Hat Enterprise Linux, RHEL and is actively developed by CentOS community which have large number of network ... Read More

Advertisements