
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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.
Advertisements