- Related Questions & Answers
- Divide number into two parts divisible by given numbers in C++ Program
- Divide a big number into two parts that differ by k in C++ Program
- Divide a string into n equal parts - JavaScript
- Count number of ways to divide a number in parts in C++
- Divide a string in N equal parts in C++ Program
- Find the number of ways to divide number into four parts such that a = c and b = d in C++
- Check if a line at 45 degree can divide the plane into two equal weight parts in C++
- How to divide an unknown integer into a given number of even parts using JavaScript?
- Java Program to divide a number into smaller random ints
- All ways to divide array of strings into parts in JavaScript
- Divide Two Integers in C++
- Splitting a string into parts in JavaScript
- Break Number Into 3 parts to find max sum
- Divide large number represented as string in C++ Program
- Splitting a string into maximum parts in JavaScript

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this tutorial, we are going to write a program that divides the given number into two parts

It'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 are

a = n / 2 b = n - a

Let's see the code.

#include <bits/stdc++.h> using namespace std; void divideTheNumber(int n) { int a = n / 2; int b = n - a; cout << a << " " << b << endl; } int main() { int n = 13; divideTheNumber(n); }

If you execute the above program, then you will get the following result.

6 7

If you have any queries in the tutorial, mention them in the comment section.

Advertisements