- 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 with sum and product both same as N.

For this we will be provided with an integer value. Our task is to find two other integer values whose product and sum is equal to the given value.

#include <bits/stdc++.h> using namespace std; //finding a and b such that //a*b=N and a+b=N void calculateTwoValues(double N) { double val = N * N - 4.0 * N; if (val < 0) { cout << "NO"; return; } double a = (N + sqrt(val)) / 2.0; double b = (N - sqrt(val)) / 2.0; cout << "Value of A:" << a << endl; cout << "Value of B:" << b << endl; } int main() { double N = 57.0; calculateTwoValues(N); return 0; }

Value of A:55.9818 Value of B:1.01819

- Related Questions & Answers
- Find two numbers with sum and product both same as N in C++ Program
- C++ program to find two numbers with sum and product both same as N
- Take two numbers m and n & return two numbers whose sum is n and product m in JavaScript
- Find N integers with given difference between product and sum in C++
- C++ find four factors of N with maximum product and sum equal to N .
- Find four factors of N with maximum product and sum equal to N in C++
- Find two distinct prime numbers with given product in C++
- Find if n can be written as product of k numbers in C++
- Maximum sum of distinct numbers with LCM as N in C++
- Find two distinct prime numbers with given product in C++ Program
- Find four factors of N with maximum product and sum equal to N - Set-2 in C++
- All possible binary numbers of length n with equal sum in both halves?
- Find the Product of first N Prime Numbers in C++
- C program to find sum and difference of two numbers
- Find product of prime numbers between 1 to n in C++

Advertisements