- 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 tutorial, we will be discussing a program to find two numbers (say ‘a’ and ‘b’) such that both

a+b = N and a*b = N are satisfied.

Eliminating ‘a’ from both the equations, we get a quadratic equation in ‘b’ and ‘N’ i.e

b^{2}- bN + N = 0

This equation will have two roots which will give us the value of both ‘a’ and ‘b’. Using the determinant method to find the roots, we get the value of ‘a’ and ‘b’ as,

$a= (N-\sqrt{N*N-4N)}/2\\ b= (N+\sqrt{N*N-4N)}/2 $

#include <iostream> //header file for the square root function #include <math.h> using namespace std; int main() { float N = 12,a,b; cin >> N; //using determinant method to find roots a = (N + sqrt(N*N - 4*N))/2; b = (N - sqrt(N*N - 4*N))/2; cout << "The two integers are :" << endl; cout << "a - " << a << endl; cout << "b - " << b << endl; return 0; }

The two integers are : a - 10.899 b - 1.10102

- Related Questions & Answers
- Find two numbers with sum and product both same as N in C++ Program
- Find two numbers with sum and product both same as N in C++
- Take two numbers m and n & return two numbers whose sum is n and product m in JavaScript
- C++ find four factors of N with maximum product and sum equal to N .
- C program to find sum and difference of two numbers
- Find two distinct prime numbers with given product in C++ Program
- Find four factors of N with maximum product and sum equal to N in C++
- Find N integers with given difference between product and sum in C++
- Find if n can be written as product of k numbers in C++
- Find two distinct prime numbers with given product in C++
- Program to find tuple with same product in Python
- Find four factors of N with maximum product and sum equal to N - Set-2 in C++
- Find four factors of N with maximum product and sum equal to N - Set-2 in Python Program
- Maximum sum of distinct numbers with LCM as N in C++
- Program to find sum of first n natural numbers in C++

Advertisements