

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 number into two parts in C++ Program
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
Example
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); }
Output
If you execute the above program, then you will get the following result.
6 7
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- 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
- C++ Partition a Number into Two Divisible Parts
- Divide a string into n equal parts - JavaScript
- Count number of ways to divide a number in parts in C++
- How to divide an unknown integer into a given number of even parts using JavaScript?
- Divide a string in N equal parts in C++ Program
- Java Program to divide a number into smaller random ints
- All ways to divide array of strings into parts in JavaScript
- Check if a line at 45 degree can divide the plane into two equal weight parts in C++
- Find the number of ways to divide number into four parts such that a = c and b = d in C++
- Java Program to divide a string in 'N' equal parts
- Program to find maximum score by splitting binary strings into two parts in Python
- Splitting a string into parts in JavaScript
- Break Number Into 3 parts to find max sum
Advertisements