
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find the number of ways to divide number into four parts such that a = c and b = d in C++
Suppose we have a number n. We have to find number of ways to divide a number into parts (a, b, c and d) such that a = c, and b = d. So if the number is 20, then output will be 4. As [1, 1, 9, 9], [2, 2, 8, 8], [3, 3, 7, 7] and [4, 4, 6, 6]
So if N is odd, then answer will be 0. If the number is divisible by 4, then answer will be n/4 – 1 otherwise n/4.
Example
#include <iostream> using namespace std; int countPossiblity(int num) { if (num % 2 == 1) return 0; else if (num % 4 == 0) return num / 4 - 1; else return num / 4; } int main() { int n = 20; cout << "Number of possibilities: " << countPossiblity(n); }
Output
Number of possibilities: 4
- Related Articles
- Count number of ways to divide a number in parts in C++
- Divide a number into two parts in C++ Program
- Divide a big number into two parts that differ by k in C++ Program
- Find four elements a, b, c and d in an array such that a+b = c+d in C++
- Find count of digits in a number that divide the number in C++
- All ways to divide array of strings into parts in JavaScript
- Divide number into two parts divisible by given numbers in C++ Program
- C++ Program to Find number of Ways to Partition a word such that each word is a Palindrome
- Find the coordinates of the points which divide the line segment joining $A (-2, 2)$ and $B (2, 8)$ into four equal parts.
- How to divide an unknown integer into a given number of even parts using JavaScript?
- Possible cuts of a number such that maximum parts are divisible by 3 in C++
- Draw an angle of measure \( 153^{\circ} \) and divide it into four equal parts.
- Find largest d in array such that a + b + c = d in C++
- C++ Partition a Number into Two Divisible Parts
- Count number of triplets (a, b, c) such that a^2 + b^2 = c^2 and 1

Advertisements