Found 7347 Articles for C++

Divisible by 37 for large numbers in C++ Program

Hafeezul Kareem
Updated on 28-Jan-2021 06:45:55

141 Views

In this tutorial, we are going to write a program that checks whether the given large number is divisible by 37 or not.We are going to use a little bit of math here. Let's see the steps to solve the problem.Initialize the number.If the length of the given number is not divisible by 3, then add zeroes at the beginning of the number to make length is divisible by 3.Divide the number into 3 digits groups and add them.If the resultant sum is divisible by 37, then the given number is divisible by 37.If the resultant sum is 4 digits ... Read More

Divisibility by 64 with removal of bits allowed in C++ Program

Hafeezul Kareem
Updated on 28-Jan-2021 06:44:33

135 Views

In this tutorial, we are going to write a program that checks whether the given binary number is divisible by 64 or not.We have given a binary number and we can remove the bits to make it divisible by 64. After removing the bits, if the number is divisible by 64, then print Yes else No.The method that we are going to use is very simple. Let's see the steps to solve the problem.Initialize the binary number in string format.Iterate over the given binary number.Count the number of zeros.If the binary number contains more than or equal to 6 and ... Read More

Divisibility by 12 for a large number in C++ Program

Hafeezul Kareem
Updated on 28-Jan-2021 06:42:37

130 Views

In this tutorial, we are going to write a program that checks whether the given large number in string format is divisible by 12 or not.We are going to use a little bit of math to solve this problem. If the number is divisible by 3 and 4, then the number will divisible by 12.A number is divisible by 3 if the sum of its digits is divisible by 3.A number is divisible by 4 if the last two digits of the number are divisible by 4.We are going to utilize the above statements and complete the program.ExampleLet's see the ... Read More

Divide the given linked list in two lists of size ratio p:q in C++ Program

Hafeezul Kareem
Updated on 28-Jan-2021 06:41:00

94 Views

In this tutorial, we are going to write a program that divides the given linked list into a p:q ratioIt's a straightforward program. Let's see the steps to solve the problem.Create a struct for the linked list node.Initialize the linked list with dummy data.Initialize the p:q ratio.Find the length of the linked list.If the length of the linked list is less than p + q, then it's not possible to divide the linked into a p:q ratio.Else iterate the linked list until p.After the p iterations, remove the link and create a new head for the second linked list.Now, print ... Read More

Divide number into two parts divisible by given numbers in C++ Program

Hafeezul Kareem
Updated on 28-Jan-2021 06:39:27

461 Views

In this tutorial, we are going to write a program that divides a number into two parts which are divisible by the given numbers.We have given a number in string format and two other integers. The program should return whether it's possible to divide the given number into two parts such that the first part is divisible by the first number and the second part is divisible by the second part.Let's see the steps to solve the problem.Initialize the number and two integers for the division.Iterate over the number until the first part is divisible by the first number.Form the ... Read More

Divide large number represented as string in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:50:21

3K+ Views

In this tutorial, we are going to learn how to divide a large number that is represented as a string.We have given a large number in string format and a divisor. Our program should find a reminder.First, we will find a part of the given number that is greater than the dividend. And then we will add the remaining digits one by one to the divisor.Let's see the steps to solve the problem.Initialize the large number along with a divisor.Iterate over the given number until we extract the part that is greater than the divisor.Now, iterate from where we left ... Read More

Divide every element of one array by other array elements in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:49:35

810 Views

In this tutorial, we are going to write a program that divides one array of elements by another array of elements.Here, we are following a simple method to complete the problem. Let's see the steps to solve the problem.Initialize the two arrays.Iterate through the second array and find the product of the elements.Iterate through the first array and divide each element with a product of the second array elements.ExampleLet's see the code. Live Demo#include using namespace std; void divideArrOneWithTwo(int arr_one[], int arr_two[], int n, int m) {    int arr_two_elements_product = 1;    for (int i = 0; i < ... Read More

Divide a string in N equal parts in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:48:23

824 Views

In this tutorial, we are going to write a program that divides the given string into N equal parts.If we can't divide the string into N equal parts, then print the same thing. Let's see the steps to solve the problem.Initialize the string and N.Find the length of the string using the size method.Check whether the string can be divided into N parts or not.If string can't divide into N equal parts, then print a message.Else iterate through the string and print each part.ExampleLet's see the code. Live Demo#include using namespace std; void divideTheString(string str, int n) {    int ... Read More

Divide a number into two parts in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:46:26

607 Views

In this tutorial, we are going to write a program that divides the given number into two partsIt's a straightforward problem to solve. We can get a number by diving the given number. And we can get the second number by subtracting the result from the total.If the given number is n, then the two numbers area = n / 2 b = n - aExampleLet's see the code. Live Demo#include using namespace std; void divideTheNumber(int n) {    int a = n / 2;    int b = n - a;    cout

Divide a big number into two parts that differ by k in C++ Program

Hafeezul Kareem
Updated on 27-Jan-2021 12:46:05

104 Views

In this tutorial, we are going to write a program that divides a number into two parts with a difference of k.Let's see an example.Inputn = 100 k = 30Output65 35Here, we need to understand a little bit of math before diving into the problem. Let's see it.We have a + b = n and a - b = k. By adding the two equations, we geta = (n + k)/2 b = n - aExampleThat's it. We have n and k. And there is nothing more in it. Let's see the code Live Demo#include using namespace std; void divideTheNumber(int ... Read More

Advertisements