Given two numbers, the task is to find the number of carry operations required when two numbers are added as below.
Input: n = 1234, k = 5678 Output: 6912 4+8 = 2 and carry 1 carry+3+7 = carry 1 carry+2+6 = 9, carry 0 carry+1+5 = 6 Input: n = 555, k = 555 Output: 3
Approach: Store the values of n and k in strings.
- Initialise the carry variable and count variable to 0.
- Now, check from the last index of the strings till both the strings come to an end(one string may be smaller than the other).
- Add both the values(take care of ascii value) with carry in every iteration and check if that sum is greater than 10 or not.
- If it is greater than 10 then simply increment the value of count by 1 and make carry equal to 1, else make carry equal to 0.
- At last, print your answer which is count.
Below is the implementation of above approach:
- Count of carry operations on adding two Binary numbers
- Addition of two numbers without propagating Carry
- Count the number of operations required to reduce the given number
- Minimum operations required to make two numbers equal
- Minimum number of given operations required to make two strings equal
- Minimum number of operations required to make two strings equal
- Add two numbers represented by two arrays
- Count of minimum reductions required to get the required sum K
- Count operations of the given type required to reduce N to 0
- Count of decrement operations required to obtain K in N steps
- Minimum number of operations required to reduce N to 1
- Minimum number of given operations required to convert a string to another string
- Minimum number operations required to convert n to m | Set-2
- Find the minimum number of operations required to make all array elements equal
- Minimum number of given operations required to reduce the array to 0 element
- Minimum number of operations required to obtain a given Binary String
- Minimum number of steps required to obtain the given Array by the given operations
- Maximum number of operations required such that no pairs from a Matrix overlap
- Minimum number of operations required to reduce N to 0
- Minimum number of operations required to maximize the Binary String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.