Programming Articles

Page 1687 of 2547

Java program to find minimum sum of factors of a number

AmitDiwan
AmitDiwan
Updated on 09-Dec-2024 557 Views

In mathematics, the factors of a number are the integers that divide the number without leaving a remainder. For a given number, finding the minimum sum of its factors involves identifying a pair of factors whose sum is the smallest among all possible factor pairs. In this article, we will learn to find the minimum sum of factors of a number we will be using the Integer class and Math class in Java − Integer class The Java Integer class serves as a wrapper for the primitive int type, encapsulating a single integer value within an object. For Integer.MAX_VALUE, which provides ...

Read More

C++ program to convert the string into an integer

Arnab Chakraborty
Arnab Chakraborty
Updated on 09-Dec-2024 13K+ Views

C++ is a statically typed language. To write programs we need to define variables of specified types. Sometimes we need to read inputs from the console or files. In such a scenario the string data are read into the program. To convert them into other datatypes needs special operations. In this article, we shall discuss how to convert strings to integers in C++. There are a few different techniques to do so. Let us explore them one by one. String to Integer Using stringstream Class C++ uses streams for different applications. Such streams are filestreams, standard input/output streams, etc. There ...

Read More

5 Different methods to find length of a string in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 05-Dec-2024 12K+ Views

Here we will see five different ways to get the string lengths in C++. In C++ we can use the traditional character array string, and C++ also has String class. In different area there are different methods of calculating the string lengths. The C++ String class has length() and size() function. These can be used to get the length of a string type object. To get the length of the traditional C like strings, we can use the strlen() function. That is present under the cstring header file. Another two approaches are straight forward. One by using the while loop, ...

Read More

Java Program for Gnome Sort

AmitDiwan
AmitDiwan
Updated on 04-Dec-2024 516 Views

Gnome Sort, also known as Stupid Sort, is a simple sorting algorithm that works by iterating through a list, comparing adjacent elements, and swapping them if they are in the wrong order. If a swap occurs, the algorithm moves one step backward to recheck the order, otherwise, it moves forward. This process continues until the array is sorted. In this article, we will explain the working of Gnome Sort using Java. Gnome Sort Approach Start from the first element. Compare the current element with the previous one: ...

Read More

Java program to check if all digits of a number divide it

AmitDiwan
AmitDiwan
Updated on 03-Dec-2024 393 Views

The given article involves determining if all digits of a positive integer can divide the number without leaving a remainder. If any digit is zero or does not divide the number the result is false; otherwise, it is true using Java. This can be solved using two approaches: the Naive-Based Approach, which relies on arithmetic operations, and the String-Based Approach, which uses string manipulation for digit processing. Both methods ensure each digit meets the divisibility condition efficiently. Approaches to Check If All Digits of a Number Divide It Following are the different approaches to check if all digits of a ...

Read More

Type Inference in C++ (auto and decltype)

Ayush Gupta
Ayush Gupta
Updated on 03-Dec-2024 343 Views

In this tutorial, we will be discussing a program to understand Type interference in C++ (auto and decltype). In the case of auto keyword, the type of the variable is defined from the type of its initializer. Further, with decltype, it lets you extract the type of variable from the called element. auto type Example Here is the following example of auto-type in C++. #include using namespace std; int main() { auto x = 4; auto y = 3.37; auto ptr = & x; cout

Read More

Bitwise AND of N binary strings in C++

sudhir sharma
sudhir sharma
Updated on 03-Dec-2024 804 Views

In this problem, we are given an array bin[] of size n of binary strings. Our task is to create a program to find the Bitwise AND (&) of N binary strings. Here, we will take all numbers and find the bitwise AND of them i.e. bin[0] & bin[1] &... bin[n-2] & bin[n] Example Let’s take an example to understand the problem. Input − bin[] = {“1001”, “11001”, “010101”} Output − 000001 Explanation Bitwise AND of all binary strings − (1001) & (11001) & (010101) = 000001 To solve this problem, ...

Read More

Largest gap in an array in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 03-Dec-2024 381 Views

In this tutorial, we are going to write a program that finds the largest difference between the two elements in the given array. Approach Let's look at the approach we will follow to solve this problem. Firstly, we will initialize the array. Then we will find or search for the max and min elements in the array. And will return max - min. Example Here is the following code for finding the largest gap in an array in C++. #include using namespace std; ...

Read More

Structure vs class in C++

Nishtha Thakur
Nishtha Thakur
Updated on 03-Dec-2024 365 Views

In C++ the structure and class are basically the same. But there are some minor differences. These differences are like below. The class members are private by default, but members of structures are public. Let us see these two codes to see the differences. Example Code for Class Here is the following code for the class. #include using namespace std; class my_class {   public:  int x = 10; }; int main() {  my_class my_ob;  cout

Read More

C++ Program to Perform Complex Number Multiplication

Ankith Reddy
Ankith Reddy
Updated on 03-Dec-2024 7K+ Views

Complex numbers are numbers that are expressed as a+bi, where i is an imaginary number and a and b, are real numbers. Some examples of complex numbers are − 2+3i 5+9i 4+2i Example A program to perform complex number multiplication is as follows − #include using namespace std; int main(){  int x1, y1, x2, y2, x3, y3;  cout y1;  cout y2;  x3 = x1 * x2 - y1 * y2;  y3 = x1 * y2 + y1 * x2;  cout

Read More
Showing 16861–16870 of 25,466 articles
Advertisements