- 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

In this problem, we are given a linear equation of n variable for the form,

coeff1(var1) + coeff2(var2) + … + coeffn(varn) = value

Find the number of solutions of a linear equation of n variables.

**Let’s take an example to understand the problem,**

coeff[] = {3, 1}, value = 4

1

Equation : 3x + y = 4. Solution, x = 0, y = 4.

A simple solution to the problem is by evaluating the value of the equation. Then update the values by calling it recursively. If the value is 0, then solution count is 1. Else recur with value by subtracting coeff values.

**Program to illustrate the working of our solution,**

#include<iostream> using namespace std; int countSolutionsEq(int coeff[], int start, int end, int value) { if (value == 0) return 1; int coefCount = 0; for (int i = start; i <= end; i++) if (coeff[i] <= value) coefCount += countSolutionsEq(coeff, i, end, value - coeff[i]); return coefCount; } int main() { int coeff[] = {3, 5, 1, 2}; int value = 6; int n = sizeof(coeff) / sizeof(coeff[0]); cout<<"The number of solutions of the linear equation is "<<countSolutionsEq(coeff, 0, n - 1, value); return 0; }

The number of solutions of the linear equation is 8

- Related Questions & Answers
- Program to find number of solutions in Quadratic Equation in C++
- Find the Number of Solutions of n = x + n x using C++
- Find the Number of solutions for the equation x + y + z <= n using C++
- Number of non-negative integral solutions of sum equation in C++
- C program to find the solution of linear equation
- Number of integral solutions of the equation x1 + x2 +…. + xN = k in C++
- Computing zeroes (solutions) of a mathematical equation in JavaScript
- Finding all solutions of a Diophantine equation using JavaScript
- Find the Number of Sextuplets that Satisfy an Equation using C++
- C/C++ Program for Number of solutions to Modular Equations?
- Program for Number of solutions to Modular Equations in C/C++?
- C++ Program to Find All Roots of a Quadratic Equation
- Find a sorted subsequence of size 3 in linear time in Python\n
- Find M-th number whose repeated sum of digits of a number is N in C++
- C/C++ Program for Number of solutions to the Modular Equations?

Advertisements