Programming Articles

Page 684 of 2544

Check if a number can be expressed as a^b in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 370 Views

Here we will check whether we can represent a number like ab or not. Suppose a number 125 is present. This can be represented as 53. Another number 91 cannot be represented as power of some integer value.AlgorithmisRepresentPower(num): Begin    if num = 1, then return true    for i := 2, i2

Read More

Traversing contents of a hash map in Java

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 787 Views

A map is a collection in Java which stores key-value pairs. The keys of this must not be null and each key should point to only one value. It is represented by the Map interface of java.util package. There are various classes which provide implementation to this interface.The HashMap is a class which implements the Map interface. It is based on the Hash table. It allows null values and null keys.In short, you can store key-value pairs in the HashMap object. Once you do so you can retrieve the values of the respective keys but, the values we use for ...

Read More

Sort an array according to the order defined by another array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 400 Views

In this section we will see another sorting problem. Suppose we have two arrays A1 and A2. We have to sort A1 in such a way that the relative order among the elements will be same as those are in A2. If some elements are not present in A2, then they will be appended after the sorted elements. Suppose A1 and A2 are the following −A1 = {2, 1, 2, 1, 7, 5, 9, 3, 8, 6, 8} A2 = {2, 1, 8, 3}After the sorting A1 will be like below −A1 = {2, 2, 1, 1, 8, 8, 3, ...

Read More

Check if a given mobile number is fancy in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 670 Views

We have a 10 digit mobile number, our task is to check whether the number is fancy number or not. There are three different conditions for a fancy number. If at least one is true, then the number is fancy. These conditions are like below −A single number occurs three consecutive times, like 555Three consecutive numbers are either in increasing or decreasing order like 123 or 321.A single digit occurs four or more times in a number, like 8965499259, here 9 has occurred four times.One example of fancy number is 9859009976, this is a fancy number as the third condition ...

Read More

How to import classes from within another directory/package in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 7K+ Views

In Java classes and interfaces related to each other are grouped under a package. The package is nothing but a directory storing classes and interfaces of a particular concept. For example, all the classes and interfaces related to input and output operations are stored in the java.io package.There are two types of packages namely user-defined packages and built-in packages (pre-defined)The import keywordWhenever you need to use the classes from a particular package −First of all, you need to set a classpath for the JAR file holding the required package.Import the required class from the package using the import keyword. While ...

Read More

_Generic keyword in C ? 1: 20

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 903 Views

_Generic keyword in C is used to define MACRO for different data types. This new keyword was added to the C programming language in C11 standard release. the _Generic keyword is used to help the programmer use the MACRO in a more efficient way.this keyword translate the MACRO based on the type of the variable. let's take an example ,#define dec(x) _Generic((x), long double : decl, \ default : Inc , \ float: incf )(x)The above syntax is how to declare any MACRO as generic for different methods.Let's take an example code, this code will define a MACRO that will ...

Read More

Program for Volume and Surface area of Frustum of Cone in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 732 Views

What is Frustrum of cone?Frustum of a cone is formed by cutting the tip of a cone leaving lower and upper base known as frustum as shown in the figure. The upper base of frustum will have radius ‘r’, lower base will have radius ‘R’ with height ‘h’ and slant height ‘L’Given below is the figure of Frustrum of coneProblemGiven with slant height, height, upper base radius ‘r’ and lower radius ‘R’, the task is to calculate the volume and surface area of Frustum of cone.To calculate the volume and surface area of Frustum of cone there is a formulaVolume ...

Read More

Check if a number can be represented as a sum of 2 triangular numbers in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 232 Views

In this section, we will see if we can express one number as the sum of two triangular numbers or not. The triangular numbers are like below −From the example, we can see that 1, 3, 6, 10 are some triangular numbers. We need to express a number N (say 16) as sum of two triangular numbers (6, 10).The approach is very simple. We have to get all triangular numbers less than N. Form a set from these values. Now we have to take a number say X from the set, and check whether N – X is present in ...

Read More

Check if a given number can be represented in given a no. of digits in any base in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 194 Views

Suppose we have a number n, and number of digits d. We have to check whether the number n can be represented as d digit number in any base from 2 to 32. Suppose the number n is 8, and d = 4, then this can be represented as 1000 in binary, here the d is 4.The idea is to check all bases one by one from 2 to 32. We can follow these steps to check the base.If the number is smaller than base, and digit is 1, then return trueif digit is more than one and number is ...

Read More

Assigning arrays in Java.

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 9K+ Views

While creating variables first of all we will declare them, initialize them, assign/re-assign values to them.Similarly, while creating arrays −You can declare an array just like a variable −int myArray[];You can create an array just like an object using the new keyword −myArray = new int[5];You can initialize the array by assigning values to all the elements one by one using the index −myArray [0] = 101; myArray [1] = 102;Assigning values to an arrayWhen we assign primitive values of one type to a variable of other (datatype) implicitly they are converted.But, when you try to assign a higher datatype ...

Read More
Showing 6831–6840 of 25,433 articles
« Prev 1 682 683 684 685 686 2544 Next »
Advertisements