- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Divide a big number into two parts that differ by k in C++ Program
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.
Input
n = 100 k = 30
Output
65 35
Here, 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 get
a = (n + k)/2 b = n - a
Example
That's it. We have n and k. And there is nothing more in it. Let's see the code
#include <bits/stdc++.h> using namespace std; void divideTheNumber(int n, int k) { double a = (n + k) / 2; double b = n - a; cout << a << " " << b << endl; } int main() { int n = 54, k = 12; divideTheNumber(n, k); }
Output
If you run the above code, then you will get the following result.
33 21
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- Related Articles
- Divide a number into two parts in C++ Program
- Divide number into two parts divisible by given numbers in C++ Program
- Find the number of ways to divide number into four parts such that a = c and b = d in C++
- Divide 72 into two parts, so that the larger part exceeds the smaller part by 12. Find both the parts.
- C++ Partition a Number into Two Divisible Parts
- Divide 29 into two parts so that the sum of the squares of the parts is 425.
- Count number of ways to divide a number in parts in C++
- Divide a string in N equal parts in C++ Program
- Divide a string into n equal parts - JavaScript
- Check if a line at 45 degree can divide the plane into two equal weight parts in C++
- divide $184$ into two parts such that one-third of one part may exceed one-seventh of the other part by $8$.
- How to divide an unknown integer into a given number of even parts using JavaScript?
- Program to find maximum score by splitting binary strings into two parts in Python
- Java Program to divide a number into smaller random ints
- Program to count substrings that differ by one character in Python

Advertisements