
- 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 two numbers with sum and product both same as N in C++
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.
Example
#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; }
Output
Value of A:55.9818 Value of B:1.01819
- Related Articles
- 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 two numbers whose product is $-24$ and sum is 2.
- Find two numbers whose sum is 27 and product is 182.
- Find N integers with given difference between product and sum in C++
- The product of two numbers is 24 and their sum is 14. Find the numbers.
- The sum of two numbers is 48 and their product is 432. Find the numbers.
- All possible binary numbers of length n with equal sum in both halves?
- Find four factors of N with maximum product and sum equal to N in C++
- C++ find four factors of N with maximum product and sum equal to N .
- Find a quadratic polynomial with the given numbers as the sum and product of zeroes respectively: $1,\ 1$.
- Find a quadratic polynomial with the given numbers as the sum and product of zeroes respectively: $4,\ 1$
- Maximum sum of distinct numbers with LCM as N in C++
- Find two distinct prime numbers with given product in C++

Advertisements