Found 7197 Articles for C++

C++ Program for quotient and remainder of big number

Sunidhi Bansal
Updated on 20-Nov-2019 12:15:19

407 Views

Given a sting of a big number say num and another big number say m; the task is to print the quotient using divide operation and the remainder of the big number using modulus.The output should be Remainder = xxx; Quotient = yyyLet’s assume we have an input num = string num = "14598499948265358486" and other input m = 487 so the remainder is 430 and quotient is 29976385930729688.ExampleInput: num = “214755974562154868”    m = 17 Output: Remainder = 15    quotient = 12632704386009109 Input: num =“214”    m = 5 Output: Remainder = 4    Quotient = 42Approach we ... Read More

Program to check Strength of Password in C++

Sunidhi Bansal
Updated on 20-Nov-2019 10:14:56

7K+ Views

Given a string input containing password characters, the task is to check the strength of the password.The strength of the password is when you tell that the password is whether easily guessed or cracked. The strength should vary from weak, average and strong. To check the strength we have to check the following points −Password must be at least 8 characters long.It must contain 1 lower case alphabet.It must contain 1 uppercase alphabetIt must contain a digitIt must contain a special character like : !@#$%^&*()>= 8))          Print "Strong"       else if ((hasLower || hasUpper) ... Read More

C++ Balanced expressions such that given positions have opening brackets

sudhir sharma
Updated on 13-Nov-2019 11:30:34

253 Views

A balanced expression of parentheses is an expression that contains pairs of all sort of parentheses together in a correct order. this means that for every opening parentheses there is a closing parentheses in proper order of parentheses i.e. { }.Expression − {([][]{})({}[]{})}Output − balancedNow, in this problem we have to create all possiblebalanced expressions from the given number of brackets.And the condition is that the given position have opening brackets.In this problem, we are given an integer n and an array of position of the brackets of length 2n and we have to find the number of balanced expressions ... Read More

C++ Balanced expression with replacement

sudhir sharma
Updated on 09-Jul-2020 05:51:04

403 Views

A balanced expression of parentheses is an expression that contains pairs of all sort of parentheses together in a correct order.this means that for every opening parentheses there is a closing parentheses in proper order of parentheses i.e. { }.let's take a few examples to understand the concept better −Expression − {([][]{})({}[]{})}Output − balancedExplanation − we can see that for every opening parentheses there is a closing parentheses. all the parentheses lying between an opening parentheses and closing parentheses in Pairs.Output − not balanceExplanation − there are some unordered pairs of parentheses which makes the the expression unbalanced.In this problem ... Read More

Balance pans using given weights that are powers of a number in C++ program

sudhir sharma
Updated on 09-Jul-2020 05:51:39

182 Views

STATEMENT − Balance pans using given weights that are powers of a number.DESCRIPTION − In this problem we are given a pan based weighing machine. we are given a weight T and some other weights whose values are powers of a number a. We need to balance the pans using the given weights.Now, based on this we have this equation, T + (some power of a) = (some other power of a)Now, we should remember that there is exactly one weight corresponding to a power value.Example, T = 12 : a = 4Using the below values, we can balance the ... Read More

Bakhshali Approximation for computing square roots in C program

sudhir sharma
Updated on 09-Jul-2020 05:52:06

712 Views

Bakhshali approximation is a method of computing the square root of a number which is not a perfect square. Now, lets brush-related terms to easily understand the concept.Square root of a number x is a number that satisfies the following condition, y2 = x.Perfect Square is a number whose square roots are w. For example 16 is perfect square as its roots are 4 and 4.There are multiple methods defined mathematically to find the square root of a number. In this tutorial, we are going to learn about Bakhshali approximation to find the square root of a number.It is a ... Read More

Find the smallest number X such that X! contains at least Y trailing zeros in C++

Arnab Chakraborty
Updated on 04-Nov-2019 10:06:31

121 Views

We have to take a number Y, we will find smallest number X, such that X! contains at least Y number of training zeros. For example, if Y = 2, then the value of X = 10. As X! = 3228800. It has Y number of zeros.We can solve this using binary search. The number of trailing zeros in N! is given by the count of the factors 5 in N!. X can be found using binary search in range [0, 5*Y]Example #include using namespace std; int factorCount(int n, int X) {    if (X < n)       ... Read More

Find the smallest and second smallest elements in an array in C++

Arnab Chakraborty
Updated on 04-Nov-2019 10:03:23

2K+ Views

Suppose we have an array of n elements. We have to find the first, second smallest elements in the array. First smallest is the minimum of the array, second smallest is minimum but larger than the first smallest number.Scan through each element, then check the element, and relate the condition for first, and second smallest elements conditions to solve this problem.Example #include using namespace std; int getTwoSmallest(int arr[], int n) {    int first = INT_MAX, sec = INT_MAX;    for (int i = 0; i < n; i++) {       if (arr[i] < first) {     ... Read More

Find the product of last N nodes of the given Linked List in C++

Arnab Chakraborty
Updated on 04-Nov-2019 09:59:11

153 Views

Consider we have few elements in a linked list. We have to find the multiplication result of last n number of elements. The value of n is also given. So if the list is like [5, 7, 3, 5, 6, 9], and n = 3, then result will be 5 * 6 * 9 = 270.The process is straight forward. We simply read the current element starting from left side, then add the elements into stack. After filling up the stack, remove n elements and multiply them with the prod. (initially prod is 1), when n number of elements are ... Read More

Find the product of first k nodes of the given Linked List in C++

Arnab Chakraborty
Updated on 04-Nov-2019 08:17:25

106 Views

Consider we have few elements in a linked list. We have to find the multiplication result of first k number of elements. The value of k is also given. So if the list is like [5, 7, 3, 5, 6, 9], and k = 3, then result will be 5 * 7 * 3 = 105.The processes is straight forward. We simply read the current element starting from left side, then multiply it with the prod. (initially prod is 1), when k number of elements are traversed, then stop.Example#include #include using namespace std;    class Node{       public: ... Read More

Advertisements